【问题标题】:Get particular content from ckeditor从 ckeditor 获取特定内容
【发布时间】:2012-12-13 14:07:23
【问题描述】:

我有一个 ckeditor,下面是我用于 ckeditor 的 textarea 及其内容以及如何使用 jquery 仅在 <p id="footer"></p> 内获取内容

<textarea id="cheditor_text" name="cheditor_text" rows="10">
<p> welcome to our company </p>
<p id="footer">
Copy right @ exak=mple.com
</p>
</textarea>

【问题讨论】:

    标签: php jquery ckeditor


    【解决方案1】:

    阅读此链接, 很有帮助。

    尝试使用getData();

    Useful Link

    【讨论】:

    • 您提出的是一条需要正则表达式来提取#footer 内容的硬路径。
    【解决方案2】:

    您甚至可以直接从编辑器中检索此元素的内容:

    CKEDITOR.instances.your_editor_instance.document.getById( 'footer' ).getHtml();
    

    但是我认为你想做的事情的逻辑有问题。如果用户省略id 属性或使用它两次,以这种方式检索内容可能会很危险。这是你不能依赖的东西。

    您最好创建两个编辑器,一个用于内容,另一个用于#footer。另一种可能性是 CKEditor 4 中引入的inline editing feature,它允许按原样编辑网页。在我看来,您真的应该重新考虑您的想法,以使其稳定可靠。

    【讨论】:

      【解决方案3】:

      你可以这样做,

      Live Demo

      txt = $('#cheditor_text').text();
      html = $('<div>').append(txt).find('#footer').prev()[0].outerHTML;
      

      不使用 outHTML

      Live Demo

      txt = $('#cheditor_text').text();
      pTag = $('<div>').append(txt).find('#footer').prev();
      alert($('<div>').append(pTag).html())​
      

      【讨论】:

        【解决方案4】:

        试试

        var value = CKEDITOR.instances['cheditor_text'].getData();
        $(value).find('#footer').html();
        

        或

        $('#cheditor_text').ckeditor(function( textarea ){
        $($(textarea).val()).find('#footer').html();
        });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-07-04
          • 2016-11-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-10-16
          • 1970-01-01
          • 2017-04-14
          相关资源
          最近更新 更多