我们有一些代码用于验证在 blur 上运行的 CKEditor textarea 上的输入。我们向所有使用 CKEditor 的文本区域添加一个类 ckeditor_textarea
并运行此代码以将必要的功能附加到模糊事件:
$("textarea.ckeditor_textarea").each(function(){
var textarea_id = $(this).attr("id");
CKEDITOR.instances[textarea_id].on('blur',function(){
// Validation functions here
});
});
这可以在模糊事件发生时触发验证函数。但是我们还需要在按下提交按钮时手动触发模糊事件,以便在提交前在这些 CKEditor 文本区域上运行验证功能。
如何触发 CKEditor 文本区域上的模糊事件?使用 jQuery 语法(这当然不起作用,因为 CKEditor 实例不是 jQuery 对象),我基本上是在寻找这样的东西:
$("textarea.ckeditor_textarea").each(function(){
var textarea_id = $(this).attr("id");
CKEDITOR.instances[textarea_id].trigger('blur');
});
最佳答案
您不应混合使用 jQuery 事件和 CKEDITOR 事件。如果您想对 CKEDITOR 实例进行模糊处理,请注册它:
ckeInst.on('模糊', 函数(e){
});
然后,如果你真的想触发模糊事件,你可以这样做:
ckeInst.focusManager.blur( true );
编辑器是从事件(如果有的话)中获取的,或者通过 CKEDITOR.instances['yourCkeName'];
关于javascript - 如何在 CKEditor textareas 上触发模糊事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32831705/