这是ckeditor4-angular中一个元素的源代码,我想附加click事件来实现自定义功能
<div class="fractional-block" id="fractional-block"><span>5</span><svg height="5" width="100%"><line stroke="#000" stroke-width="2" x1="0" x2="100%" y1="0" y2="0"></line></svg><span>6</span></div>
我已经在编辑器的更改事件中调用了它
this.CKEDITOR.instance['fractional-block'].on('contentDom', function() {
this.document.on('click', function(event){
console.log('click', event)
});
});
但出现错误"Cannot read property 'on‘of undefined“,有人能指导我如何将点击事件附加到元素上吗?
发布于 2020-10-01 02:15:18
加载内容时,CKEditor CKEditor内部的on*属性会对on*属性进行编码,因此它们不会破坏编辑功能。例如,onmouseout在编辑器中变成data-cke-pa-onmouseout,然后,当从编辑器获取数据时,这个属性被解码。
这里没有配置选项,因为它没有任何意义。
注意:在编辑器的可编辑元素中设置元素的属性时,应该将其设置为受保护的格式:
element.setAttribute( 'data-cke-pa-onclick','alert("blabla")‘);CKEditor中的可点击元素如果你想在编辑器中观察点击事件,那么这是正确的解决方案:
editor.on( 'contentDom', function() {
var element = editor.document.getById( 'bar' );
editor.editable().attachListener( element, 'click', function( evt ) {
// ...
// Get the event target (needed for events delegation).
evt.data.getTarget();
} );
} );
https://stackoverflow.com/questions/64138910
复制相似问题