将 ckeditor 文本提取到新的 div

extract ckeditor text to a new div

我有一个标签,一个标签有 ck 编辑器,另一个标签有预览 所以我想从ck编辑器中提取文本到预览部分(预览部分不过是一个div)

    <div class="create-tab">
      <button class="tablinks" type="button" onclick="openCity(event, 'editor')">Editor</button>
      <button class="tablinks" type="button" id="preview" onclick="openCity(event, 'preview')">Preview</button>    
   </div>


     <div id="editor" class="tabcontent">
         <textarea name="eml_html" id="textbox"></textarea>
     </div>

     <div id="preview" class="tabcontent">
          <div id="preview-area"> </div>                      
     </div>

我试过这样做但没有成功

脚本

       var editor = CKEDITOR.replace('textbox', { allowedContent:true, removePlugins:"about" }); 
        $('#preview').click(function(){
//            alert("test");
            var test = CKEDITOR.instances.yourEditorInstance.editable().getText();
            alert(test);
     });

所以当我点击预览选项卡时,我什么也没看到。

尝试用 editor 替换 yourEditorInstance。看起来那行(设置测试变量)正在尝试访问未定义的 属性 yourEditorInstance.

我能够解决这个问题,所以这就是我在 脚本 部分

中所做的
     var editor = CKEDITOR.replace('textbox', { allowedContent:true, removePlugins:"about" }); 
            $('#preview').click(function(){
    //            alert("test");
     var test = CKEDITOR.instances.textbox.editable().getText(); //if you only want text 
//var test= KEDITOR.instances.textbox.getData(); //if you want everything
                alert(test);
         });

所以我所做的是将 yourEditorInstance 替换为我的文本区域的 ID,即 textbox