如何在更改事件上检测CKEditor源模式

问题描述 投票:10回答:2

在CKEditor中,我知道在“正常模式”下,我们可以使用以下代码检测任何内容更改:

ckeditor.on('change',function(e){
  console.log("ckeditor on change");
});

但是,如果我切换到源模式,事件不会触发。

如何检测源视图的on change事件?

javascript ckeditor
2个回答
9
投票

“key”事件不会使用“change”事件,而是触发源视图。

感谢Kicker的暗示


3
投票

The CKEditor 4 documentation告诉我们不会在源模式下触发更改事件。

文档中的示例为我工作。它将侦听器绑定到mode事件。当模式改变时,这就被激发了。当它更改为源时,将侦听器附加到编辑器。

editor.on('mode', function() {
    if (this.mode === 'source') {
        var editable = editor.editable();
        editable.attachListener(editable, 'input', function() {
            // Handle changes made in the source mode.
        });
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.