我正在尝试将来自数据库的HTML数据显示到我的CKEDITOR中,问题是当我尝试使用setData插入html时,它给出了以下错误:
Uncaught SyntaxError: Invalid or unexpected token
HTML:
<label for="descricao">Descrição</label>
<textarea id="description" name="description" class="form-control descricao_anunciante" placeholder="(quem és, o que fazes ou o que representas, temas e tipos de eventos)"></textarea>
<script>
$(document).ready(function() {
CKEDITOR.replace('description', {
customConfig: './js/wysiwygconfig.js'
});
CKEDITOR.instances["description"].setData("{!! $evento->description !!}");
});
</script>
但如果尝试插入数据mannualy它的工作原理:
CKEDITOR.instances["description"].setData("<p> Hello World </p>");
来自数据库的数据:
<p>N TEM</p>
答案 0 :(得分:0)
<script>
$(document).ready(function() {
CKEDITOR.replace('description', {
customConfig: './js/wysiwygconfig.js'
});
CKEDITOR.instances["description"].setData("{{ $evento->description }}");
});
</script>
Or
instead of CKEDITOR.instances["description"].setData("{{ $evento->description }}");
you can use
<textarea id="description" name="description" class="form-control descricao_anunciante" placeholder="(quem és, o que fazes ou o que representas, temas e tipos de eventos)">
{{ $evento->description }}
</textarea>
这可以提供帮助,因为“{{}}” - 带有htmlentities函数的返回字符串。
答案 1 :(得分:0)
这个错误也来了,因为如果您要检查代码,您会看到它的给定错误,因为html进入第二行,因此它的给定语法错误只能通过设置textarea内的值来设置数据。
<textarea id="description" name="description" class="form-control descricao_anunciante" placeholder="(quem és, o que fazes ou o que representas, temas e tipos de eventos)"><?= $evento->description ?></textarea>