jquery - 如何使用 jQuery 销毁内联 CKEditor

标签 jquery ckeditor destroy

假设这是我的代码:

<div class="editor" contenteditable></div>

// This is working for me
$('.editor').click(function(){
   $(this).ckeditor();
});

// This is the problem
$('.editor').on('focusout', function(){
   $(this).ckeditorDestroy(); // What will destroy ckeditor?
});

我知道这个功能不存在,但我没有发现什么在起作用?

最佳答案

HTML

<div contenteditable="true" class="editor">Editor 1!</div>
<div contenteditable="true" class="editor">Editor 2!</div>

JS

CKEDITOR.disableAutoInline = true;

$( '.editor' ).click( function(){
    $( this ).ckeditor( function() {
        console.log( 'Instance ' + this.name + ' created' );
    }, {
        on: {
            blur: function( evt ) {
                console.log( 'Instance ' + this.name + ' destroyed' );
                this.destroy();
            }
        }
    } );
} );

使用editor#blur事件而不是 focusout 或类似事件,因为即打开编辑器对话框并不意味着编辑器模糊,而在这种情况下可能会触发 focusout 。这样更安全。 More about jQuery adapter .

关于jquery - 如何使用 jQuery 销毁内联 CKEditor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24533286/

相关文章:

javascript - CKEditor 向表单提交空内容。

javascript - CKEditor - 不显示

javascript - 防止CKEditor过滤掉 "tel"协议(protocol)

jquery - 如何在 jsdom@5 中使用 jQuery?

javascript - Firefox 中的语音识别

Jquery获取h2标签的值

android - 如果我们不需要它,如何销毁 ImageView 中的可绘制对象?

php - 以 laravel 方式销毁/重置单例

multithreading - 正确的线程销毁

javascript - 我怎么知道我的 Javascript 执行了?