【问题标题】:Html rich text editor and read-only content?Html富文本编辑器和只读内容?
【发布时间】:2010-01-19 16:33:36
【问题描述】:

我正在寻找一种方法,使 HTML 富文本编辑器中的特定元素成为只读且用户无法修改。有没有办法实现这种行为?

我所指的富文本编辑器的一个示例是这段代码 sn-p:

 <html>
 <head>
  <script type="text/javascript">
   var Editor = {
    Init: function() {
     $("#editor").get()[0].contentWindow.document.designMode = "on";
    }
   }

   $(document).ready(function() { Editor.Init(); });
  </script>
 </head>
 <body>
  <iframe id="editor" style="width: 500px; height: 250px;"></iframe>
 </body>
</html>

/托比亚斯

【问题讨论】:

    标签: jquery html richtextbox rich-text-editor designmode


    【解决方案1】:

    我不知道这是否对您有帮助,但所见即所得编辑器CKEditor 可以使用正则表达式保护内容:

    http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.protectedSource

    CKEDITOR.config.protectedSource 自:3.0 要在输入 HTML 上执行的正则表达式列表,指示必须保持不变的代码。

    config.protectedSource.push( /<\?[\s\S]*?\?>/g );   // PHP Code
    config.protectedSource.push( /<%[\s\S]*?%>/g );   // ASP Code
    config.protectedSource.push( /(]+>[\s|\S]*?<\/asp:[^\>]+>)|(]+\/>)/gi );   // ASP.Net Code
    

    我自己还没有使用过它,但从我在论坛和 SO 上听到的信息来看,它似乎工作得很好。

    不过,我使用过 CKEditor,并且可以将其推荐为可用的最佳 WYSIWYG 编辑器之一,即使文档和社区支持有点少,但它在市场上仍然很新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 1970-01-01
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      相关资源
      最近更新 更多