切换到源代码模式并返回后,我无法在 CKEditor 中使用单击事件
I can't get click event working in CKEditor after switching to Source mode and back
我在 CKEdtor 的 iframe 中设置事件处理程序如下:
CKEDITOR.on('instanceReady', function() {
$('.cke_contents iframe').contents().click(function() {
alert('Clicked!');
});
});
它运行良好,但是当我单击 'Source' 按钮时,它不再起作用(警报不起作用)。
有人可以帮助我吗???
请使用以下代码:
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。
我在 CKEdtor 的 iframe 中设置事件处理程序如下:
CKEDITOR.on('instanceReady', function() {
$('.cke_contents iframe').contents().click(function() {
alert('Clicked!');
});
});
它运行良好,但是当我单击 'Source' 按钮时,它不再起作用(警报不起作用)。
有人可以帮助我吗???
请使用以下代码:
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。