在ckeditor中插入html会导致语法错误

我在laravel中试用CKeditor,但遇到将html插入编辑器的问题。追加编辑器后,我想设置值,以便您可以编辑已经存在的值。


HTML:


@if (!empty($proposal->reference_sites))

    <div class="form-group row mb-4">

        <label for="reference_sites" class="col-sm-3 col-form-label form-control-lg">Reference sites:</label>

        <div class="col-sm-10" id="reference_sites"></div>

    </div>

@endif

JS:


if($('#reference_sites').length){

    $output = "<textarea id='ckeditor-rs' name='ckeditor-rs' rows='10' cols='80'></textarea>";

    $('#reference_sites').append($output);

    CKEDITOR.replace('ckeditor-rs');


    var editor = CKEDITOR.instances['ckeditor-rs'];

    editor.setData("{!!html_entity_decode($proposal->reference_sites)!!}");


    }else{

        console.log("couldn't append ckeditor in rs");

    }

如您所见,我正在尝试解码HTML,并将其设置为CKeditor的HTML。


$proposal->reference_sites 包含以下HTML:


<ul>

    <li>site one</li>

    <li>site two</li>

    <li>site 3</li>

</ul>

错误: Uncaught SyntaxError: Invalid or unexpected token <


我不确定是什么原因导致此错误,因为当我仅解码包含<p>some text</p>该变量的变量时,会将其插入some text到编辑器中。


任何帮助是极大的赞赏!


吃鸡游戏
浏览 255回答 2
2回答

小唯快跑啊

试试下面的一个,if($('#reference_sites').length){$output = "<textarea id='ckeditor-rs' name='ckeditor-rs' rows='10' cols='80'></textarea>";$('#reference_sites').append($output);CKEDITOR.replace('ckeditor-rs');var editor = CKEDITOR.instances['ckeditor-rs'];editor.setData("{{$proposal->reference_sites}}");}else{&nbsp; &nbsp; console.log("couldn't append ckeditor in rs");}

繁星coding

您可以尝试以下代码:if($('#reference_sites').length){&nbsp; &nbsp; $output = "<textarea id='ckeditor-rs' name='ckeditor-rs' rows='10' cols='80'></textarea>";&nbsp; &nbsp; $('#reference_sites').append($output);&nbsp; &nbsp; CKEDITOR.replace('ckeditor-rs');&nbsp; &nbsp; for (var i in CKEDITOR.instances) {&nbsp; &nbsp; &nbsp; &nbsp; CKEDITOR.instances[i].on('change', function() {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CKEDITOR.instances[i].updateElement()&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; }}else{&nbsp; &nbsp; console.log("couldn't append ckeditor in rs");}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript