猿问

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

我想在 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]

    ],

})

编辑器工作完美。

我哪里做错了?


手掌心
浏览 169回答 6
6回答

汪汪一只猫

完整代码const description = SUNEDITOR.create((document.getElementById('description')),{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buttonList: [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ['undo', 'redo'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ['bold', 'underline', 'italic'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ['removeFormat'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ['outdent', 'indent'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ['align', 'list'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ['table'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ['fullScreen', 'showBlocks']&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lang: SUNEDITOR_LANG['pl']&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; $(window).click(function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById('description').value = description.getContents();&nbsp; &nbsp; &nbsp; &nbsp; });

桃花长相依

您必须将值从 suneditor 发送到 textarea,您可以这样做:$(window).click(function()&nbsp;{&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById('txtEditor').value&nbsp;=&nbsp;txtEditor.getContents(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});

慕村9548890

无需为此编写任何 js 代码,只需将您的文本/内容放在 textarea 标记之间,就像:<textarea id="txtEditor" name="txtEditor" style="display:none;">Here is your text</textarea>OR<textarea id="txtEditor" name="txtEditor" style="display:none;">&nbsp; &nbsp;<?= $content; ?></textarea>

大话西游666

// Gets the suneditor's context object. Contains settings, plugins, and cached element objectseditor.getContext();// Gets the contents of the suneditor// onlyContents {Boolean}: Return only the contents of the body without headers when the "fullPage" option is trueeditor.getContents(onlyContents: Boolean);&nbsp; &nbsp;&nbsp;// Gets only the text of the suneditor contentseditor.getText();// Change the contents of the suneditoreditor.setContents('set contents');

收到一只叮咚

您只需要运行该instance.save()方法。const instance = SUNEDITOR.create();instance.save()

潇潇雨雨

您需要在 if 条件中使用 isset 函数,否则会抛出错误。if(isset($_POST["submit"])){&nbsp; &nbsp; $content =&nbsp; $_POST["txtEditor"];&nbsp; &nbsp; echo $content;&nbsp; &nbsp;}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答