CKEDITOR - 无法编辑文本或使用任何按钮

时间:2015-11-26 11:51:12

标签: javascript jquery ckeditor

我有一个div,点击后会打开CKEDITOR。我希望div的内容加载到编辑器中。当我点击编辑器时,我希望编辑器的内容显示在div中。

这是我的代码:

<script>
    var editor;
    $(function () {
        if (editor != null) {
            editor.destroy(true);
        }
        else {
            editor = null;
        }

        editor = CKEDITOR.replace('editor1');

       $('.textObj').on('dblclick', function () {
          $('#cke_editor1').show();       
          $("#cke_1_contents").html($('.textObj').html());
       })
       $('#cke_1_top').on('dblclick', function () {
          $('.textObj').html($('#cke_1_contents').html());
          $('#cke_editor1').hide();
       })
</script>

<div class="textObj">Here is some Text</div>
<textarea name="editor1" id="editor1" contenteditable="true"></textarea>

当我双击div时,它按预期打开编辑器,编辑器确实包含div中的文本。但是我无法编辑文本,当我点击其中一个按钮时,我收到错误:Uncaught TypeError:无法读取未定义的属性'getSelection'。

任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

你为什么要同时拥有textarea和div?

使用ckeditor内联编辑。

删除textarea。

在div中添加contenteditable =“true”。