Javascript 在ckeditor中插入html会导致语法错误(laravel)

Javascript 在ckeditor中插入html会导致语法错误(laravel),javascript,html,laravel,ckeditor,laravel-blade,Javascript,Html,Laravel,Ckeditor,Laravel Blade,我正在laravel中试用CKeditor,在将html插入编辑器时遇到了一个问题。附加编辑器后,我想设置该值,以便您可以编辑已经存在的值 HTML: 错误:Uncaught SyntaxError:无效或意外的令牌请尝试以下方法 if($('#reference_sites').length){ $output = "<textarea id='ckeditor-rs' name='ckeditor-rs' rows='10' cols='80'></textarea>

我正在laravel中试用CKeditor,在将html插入编辑器时遇到了一个问题。附加编辑器后,我想设置该值,以便您可以编辑已经存在的值

HTML:

错误:
Uncaught SyntaxError:无效或意外的令牌请尝试以下方法

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{
    console.log("couldn't append ckeditor in rs");
}
if($('reference_sites')。长度){
$output=“”;
$('reference_sites')。追加($output);
CKEDITOR.replace('CKEDITOR-rs');
var editor=CKEDITOR.instances['CKEDITOR-rs'];
setData(“{{$proposal->reference_sites}”);
}否则{
log(“无法在rs中附加ckeditor”);
}

您可以尝试以下代码:

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');

    for (var i in CKEDITOR.instances) {
        CKEDITOR.instances[i].on('change', function() { 
            CKEDITOR.instances[i].updateElement() 
        });
    }
}else{
    console.log("couldn't append ckeditor in rs");
}
if($('reference_sites')。长度){
$output=“”;
$('reference_sites')。追加($output);
CKEDITOR.replace('CKEDITOR-rs');
for(CKEDITOR.instances中的变量i){
CKEDITOR.instances[i].on('change',function(){
CKEDITOR.instances[i].updateElement()
});
}
}否则{
log(“无法在rs中附加ckeditor”);
}

尝试在没有html的情况下执行此操作,返回相同的错误,但我得到的不是html而是
ul-lisite one/li-lisite two/li-lisite 3/li/ul
editor.setData(“{$proposal->reference\u sites}”);好了,三个小时后我终于发现了问题所在。在数据库中,您也有“enter”实体,它们弄乱了javascript,因为它通常会在其中输入一个enter。这会将
{$proposal->reference_sites}
插入为html。这是变量名,而不是变量值。我假设$proposal->reference_站点包含html,您可以尝试作为html字符串编辑器进行回显。setData(“”);如果不是,那么你会犯一些语法错误,就像我在原始问题中所说的,错误是:未捕获的语法错误:无效或意外的标记<第254行检查此参考让我们检查一下。
<ul>
    <li>site one</li>
    <li>site two</li>
    <li>site 3</li>
</ul>
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{
    console.log("couldn't append ckeditor in rs");
}
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');

    for (var i in CKEDITOR.instances) {
        CKEDITOR.instances[i].on('change', function() { 
            CKEDITOR.instances[i].updateElement() 
        });
    }
}else{
    console.log("couldn't append ckeditor in rs");
}