在切换到源模式并返回后,我无法在CKEditor中使用click事件

时间:2017-10-25 12:56:28

标签: event-handling click ckeditor

我在CKEdtor的iframe中设置了事件处理程序,如下所示:

Enum2::Value

效果很好,但是当我点击“来源”按钮时,它不再起作用(警报不起作用)。

有人可以帮帮我吗???

1 个答案:

答案 0 :(得分:0)

请使用以下代码:

var editor = CKEDITOR.replace( 'editor1', { });
editor.on("pluginsLoaded", function( event ) {
    editor.on( 'contentDom', function( ) {
        var editable = editor.editable();
        editable.attachListener( editable, 'click', function( evt ) {
            console.log('click' );
        }, null, null, 10 );
    } );
} );

如果您想在切换到源模式并返回时保持点击监听器,则需要使用contentDom事件 - https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.editor-event-contentDom

请注意,您应该将听众附加到editable而不是iframe,并且您不需要jQuery。