Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用CKEDITOR绑定onchange和onkeyup?_Javascript_Jquery_Ckeditor_Ckeditor4.x - Fatal编程技术网

Javascript 如何使用CKEDITOR绑定onchange和onkeyup?

Javascript 如何使用CKEDITOR绑定onchange和onkeyup?,javascript,jquery,ckeditor,ckeditor4.x,Javascript,Jquery,Ckeditor,Ckeditor4.x,我想集成一个确认,如果我们有未保存的表单和用户取消,我们会向他显示一条消息。它可以完美地用于输入,但不适用于ckeditor。这是我的密码 $(document).ready(function () { $('form').attr('onsubmit', 'disableBeforeUnload();'); $('form input').attr('onchange', 'enableBeforeUnload();'); $('form input').attr('o

我想集成一个确认,如果我们有未保存的表单和用户取消,我们会向他显示一条消息。它可以完美地用于输入,但不适用于ckeditor。这是我的密码

$(document).ready(function () {
    $('form').attr('onsubmit', 'disableBeforeUnload();');
    $('form input').attr('onchange', 'enableBeforeUnload();');
    $('form input').attr('onkeyup', 'enableBeforeUnload();');
    $('form textarea').attr('onchange', 'enableBeforeUnload();');
    $('form textarea').attr('onkeyup', 'enableBeforeUnload();');

});

function enableBeforeUnload() {
    window.onbeforeunload = function (e) {
        return "Discard changes?";
    };
}
function disableBeforeUnload() {
    window.onbeforeunload = null;
}
有什么办法可以做到这一点吗?

有一个事件和一个事件

更改事件:当编辑器的内容更改时激发

由于性能原因,无法验证内容是否真实 改变。相反,编辑器会监视多个编辑操作 通常会导致变化。因此,在某些情况下可能会触发此事件 当没有变化发生,甚至可能被解雇两次

如果不要频繁触发更改事件很重要,那么 应在中比较上一个编辑器内容和当前编辑器内容 事件侦听器。不建议每次更改都这样做 事件

请注意,更改事件仅在所见即所得模式下触发。 为了在源代码模式下实现类似的功能,您需要 例如,可以侦听键事件或本机输入事件 由InternetExplorer8支持

按键事件:当按下任何键盘键或其组合时激发 在编辑区域中按


阅读文档。。。。
editor.on( 'mode', function() {
    if ( this.mode == 'source' ) {
        var editable = editor.editable();
        editable.attachListener( editable, 'input', function() {
            // Handle changes made in the source mode.
        } );
    }
} );
editor.on( 'key', function( evt ) {
    if ( evt.data.keyCode == CKEDITOR.CTRL + 90 ) {
        // Do something...

        // Cancel the event, so other listeners will not be executed and
        // the keydown's default behavior will be prevented.
        evt.cancel();
    }
} );