在事件侦听器插入到CKEDITOR之前添加一个元素? [英] Add event listener to an element while inserting into CKEDITOR?
问题描述
目标:
我想添加一个事件监听器到特定类型的元素(例如: span
)
我试过的内容:
我使用了$ code> contentDom CKEDITOR
,将事件侦听器添加到 span
元素。
问题:
但是,将事件侦听器添加到 span
将适用于编辑器当前可用的 span
。但是,不是将来将由用户创建的元素( span
)。我现在该怎么办?
使用事件冒泡的好处[ 1 , 2 ]。将侦听器附加到编辑器的最上面的元素(可编辑),并过滤掉事件:
CKEDITOR.replace('editor1' ,{
on:{
contentDom:function(){
this.editable()。on('click',function(evt){
var target = evt.data .getTarget();
if(target.is('span')){
console.log('clicked span!');
}
} );
}
}
});
I'm newbie to CKEDITOR. It might sound worthless to some of you to answer this questions. But, I'm struggling to find a solution for my problem for the past few hours.
Aim :
I would like to add an event listener to particular kind of element ( For ex : span
)
What i tried :
I used contentDom
event thrown by CKEDITOR
, to add the event listener to span
elements.
Problem :
However, Adding event listener to span
will be applicable for the span
which are currently available in editor. But, Not for the elements ( span
) which will be created by the user in future. What should i do now?
Use the benefits of event bubbling [1, 2]. Attach the listener to the topmost element of the editor (editable) and filter out the events:
CKEDITOR.replace( 'editor1', {
on: {
contentDom: function() {
this.editable().on( 'click', function( evt ) {
var target = evt.data.getTarget();
if ( target.is( 'span' ) ) {
console.log( 'clicked span!' );
}
} );
}
}
} );
这篇关于在事件侦听器插入到CKEDITOR之前添加一个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!