在ckeditor中为keypress添加事件监听器的代码 [英] add code for event listener for keypress in ckeditor

查看:649
本文介绍了在ckeditor中为keypress添加事件监听器的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在加载CKEditor之后为keypress添加一个事件监听器。
代码如下:

I need to add an event listener for keypress after the CKEditor is loaded. The code is something like:

CKEDITOR.instances.editor1.document.on('key', function(event) {
    /* instructions   */
});

任何想法在哪里可以添加代码?在哪个文件或以什么方式?

Any idea where can I add the code for that? In which file or in what way?

推荐答案

代码存档它是这样的:

CKEDITOR.on('instanceCreated', function(e) {
        e.editor.on('contentDom', function() {
            e.editor.document.on('keyup', function(event) {
                // keyup event in ckeditor
            }
        );
    });
}); 

编辑 - 2014 - 由于这个答案仍然有一些upvote,我觉得这是公平的点out,它是为CKEditor在版本3.x. 4.x版本有一个更改事件,它不仅会触发关键事件,还会在粘贴,撤消,重做等之后触发。

Edit - 2014 - Since this answer is still getting some upvotes, i felt it would be fair to point out, that it was meant for CKEditor in version 3.x. With the version 4.x there is a change event, which will trigger not only on key events but also after pasting, undo, redo etc.

这个:

CKEDITOR.on('instanceCreated', function(e) {
    e.editor.on('change', function (event) {
        // change event in CKEditor 4.x
    });
}); 

这篇关于在ckeditor中为keypress添加事件监听器的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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