You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CKEditor无法显示textarea的value属性内容,如何解决?

问题原因

<textarea> 标签的内容并非通过 value 属性定义,它的实际内容需要嵌套在 <textarea> 和 </textarea> 标签之间。你现在把数据库取出的内容放在 value 属性里,CKEditor 无法识别读取这部分内容,导致编辑器显示为空。

修复方法

将原本写在 value 属性中的 PHP 输出代码,直接移到 <textarea> 标签内部即可:

<script src="https://cdn.ckeditor.com/ckeditor5/34.2.0/classic/ckeditor.js"></script>
<textarea id="editor" rows="6" name="post-body"><?php echo html_entity_decode($post['content']) ?></textarea>  
<script>
    ClassicEditor
        .create( document.querySelector( '#editor' ) )
        .catch( error => {
            console.error( error );
        } );
</script>

补充说明

  • 确保数据库中存储的 $post['content'] 是经过 htmlentities() 转义后的数据,这样 html_entity_decode() 才能正确还原成 CKEditor 可解析的 HTML 内容。
  • 如果内容包含 <、> 这类特殊字符,html_entity_decode() 会将其还原为原始符号,CKEditor 就能正常加载并显示内容。

内容的提问来源于stack exchange,提问作者c.dasa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 17:10:28