【问题标题】:ckeditor adding html tags in databaseckeditor在数据库中添加html标签
【发布时间】:2015-07-16 05:38:31
【问题描述】:

我将 ckeditor 添加到我的网络管理面板

<textarea name="stateinformation" id="editor1" rows="10" cols="80">
    This is my textarea to be replaced with CKEditor.
</textarea>
<script>
    // Replace the <textarea id="editor1"> with a CKEditor
    // instance, using default configuration.
    //CKEDITOR.replace( 'editor1' );
    CKEDITOR.replace( 'editor1', {
        on: {
            instanceReady: function( ev ) {
                // Output paragraphs as <p>Text</p>.
                this.dataProcessor.writer.setRules( 'p', {
                    indent: false,
                    breakBeforeOpen: true,
                    breakAfterOpen: false,
                    breakBeforeClose: false,
                    breakAfterClose: true
                });
            }
}
});
</script>

我尝试制作一些段落和项目符号列表。但是添加到数据库中的数据看起来像这样

<p>text...</p><p>&nbsp;</p><p>&nbsp;</p><p>text...</p><ul><li>text...</li><li>text...</li><li>text...</li></ul>

我尝试使用 str_replace 和 stripslashes,但它也删除了 para 和项目符号列表效果。谁能告诉如何删除这些特殊字符而不删除它们的效果

【问题讨论】:

  • ckeditor.com/forums/CKEditor-3.x/…CKEDITOR.instances.editor1.document.getBody().getText()
  • @Tushar 您提供的链接无效。我应该把你的代码放在哪里来测试
  • 是不是表示你试图在你的编辑器中给出html标记数据?

标签: javascript html ckeditor wysiwyg


【解决方案1】:

在 Ckeditor 配置文件中放置你想要允许的标签:例如

config.allowedContent =
    'h1 h2 h3 p blockquote strong em;' +
    'a[!href];' +
    'img(left,right)[!src,alt,width,height];';

请参考Advanced Content Filter(ACF) 以获得更多帮助和示例

【讨论】:

    猜你喜欢
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 1970-01-01
    • 2018-12-21
    • 2021-03-10
    相关资源
    最近更新 更多