为了账号安全,请及时绑定邮箱和手机立即绑定

如何从 php 中的 suneditor textarea 发送值?

如何从 php 中的 suneditor textarea 发送值?

手掌心 2023-04-20 10:16:59
我想在 php Suneditor中发送 textarea 值PHP代码if($_POST["submit"]){    $content =  $_POST["txtEditor"];    echo $content;}网页代码 <form action="" method="post" >        <textarea id="txtEditor" name="txtEditor" style="display:none;"></textarea>        <input type="submit" name="submit" class="submit">    </form>Javascript$(document).ready(function() {    $("#txtEditor").Editor();    $('form').submit(function () {        $('#txtEditor').val($('#txtEditor').Editor('getText'));    });    $('#txtEditor').Editor('setText', $('#txtEditor').val());});suneditor.create('txtEditor', {    buttonList: [        ['undo', 'redo', 'removeFormat'],        [align, font, fontSize, fontColor, hiliteColor],        [horizontalRule, image, template]    ],})编辑器工作完美。我哪里做错了?
查看完整描述

6 回答

?
汪汪一只猫

TA贡献1898条经验 获得超8个赞

完整代码


const description = SUNEDITOR.create((document.getElementById('description')),{

            buttonList: [

                ['undo', 'redo'],

                ['bold', 'underline', 'italic'],

                ['removeFormat'],

                ['outdent', 'indent'],

                ['align', 'list'],

                ['table'],

                ['fullScreen', 'showBlocks']

            ],

            lang: SUNEDITOR_LANG['pl']

        });

        $(window).click(function() {

            document.getElementById('description').value = description.getContents();

        });


查看完整回答
反对 回复 2023-04-20
?
桃花长相依

TA贡献1860条经验 获得超8个赞

您必须将值从 suneditor 发送到 textarea,您可以这样做:

$(window).click(function() { 
           document.getElementById('txtEditor').value = txtEditor.getContents();
        });


查看完整回答
反对 回复 2023-04-20
?
慕村9548890

TA贡献1884条经验 获得超4个赞

无需为此编写任何 js 代码,只需将您的文本/内容放在 textarea 标记之间,就像:


<textarea id="txtEditor" name="txtEditor" style="display:none;">Here is your text</textarea>

OR

<textarea id="txtEditor" name="txtEditor" style="display:none;">

   <?= $content; ?>

</textarea>


查看完整回答
反对 回复 2023-04-20
?
大话西游666

TA贡献1817条经验 获得超14个赞

// Gets the suneditor's context object. Contains settings, plugins, and cached element objects


editor.getContext();


// Gets the contents of the suneditor

// onlyContents {Boolean}: Return only the contents of the body without headers when the "fullPage" option is true


editor.getContents(onlyContents: Boolean);    


// Gets only the text of the suneditor contents


editor.getText();


// Change the contents of the suneditor

editor.setContents('set contents');


查看完整回答
反对 回复 2023-04-20
?
收到一只叮咚

TA贡献1821条经验 获得超4个赞

您只需要运行该instance.save()方法。


const instance = SUNEDITOR.create();

instance.save()


查看完整回答
反对 回复 2023-04-20
?
潇潇雨雨

TA贡献1833条经验 获得超4个赞

您需要在 if 条件中使用 isset 函数,否则会抛出错误。


if(isset($_POST["submit"])){

    $content =  $_POST["txtEditor"];

    echo $content;

   }


查看完整回答
反对 回复 2023-04-20
  • 6 回答
  • 0 关注
  • 117 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信