假设这是我的代码:
<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/