如何在CKEditor文本区域上触发模糊事件? [英] How to trigger the blur event on CKEditor textareas?

查看:89
本文介绍了如何在CKEditor文本区域上触发模糊事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一些代码可以验证在模糊运行的CKEditor文本区域上的输入.我们向使用CKEditor的所有文本区域添加ckeditor_textarea类,并运行以下代码以将必要的函数附加到blur事件:

We have some code for validating input on a CKEditor textarea that runs on blur. We add a class of ckeditor_textarea to all textareas that use CKEditor and run this code to attach the necessary functions to the blur event:

$("textarea.ckeditor_textarea").each(function(){
    var textarea_id = $(this).attr("id");
    CKEDITOR.instances[textarea_id].on('blur',function(){
        // Validation functions here
    });
});

这在模糊事件发生时触发验证功能.但是,我们还需要在按下提交按钮时手动触发模糊事件,以便在提交之前在这些CKEditor文本区域上运行验证功能.

This works to fire the validation functions when the blur event happens. But we also need to manually trigger the blur event when the submit button is pressed to run the validation functions on these CKEditor textareas before submitting.

如何在CKEditor文本区域上触发模糊事件?使用jQuery语法(由于CKEditor实例不是jQuery对象,所以这当然不起作用),我基本上是在寻找这样的东西:

How do you trigger the blur event on a CKEditor textarea? Using jQuery syntax (which of course doesn't work because the CKEditor instance isn't a jQuery object), I'm basically looking for something like this:

$("textarea.ckeditor_textarea").each(function(){
    var textarea_id = $(this).attr("id");
    CKEDITOR.instances[textarea_id].trigger('blur');
});

推荐答案

  1. 您不应混合使用jQuery事件和CKEDITOR事件.如果您想让CKEDITOR实例模糊,请注册它:

  1. You should not mix jQuery events and CKEDITOR events. If you would like to have blur for CKEDITOR instance, register it:

ckeInst.on('blur',function(e){

ckeInst.on('blur', function(e){

});

然后,如果您确实要触发模糊事件,则可以这样操作:

And then, if you really want to trigger blur event, you do it like this:

ckeInst.focusManager.blur( true ); 

从事件(如果有)中或通过CKEDITOR.instances ['yourCkeName'];

Editor is retrived from event (if you have it), or via CKEDITOR.instances['yourCkeName'];

这篇关于如何在CKEditor文本区域上触发模糊事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆