过滤(仅限 CKEditor >=4.1)
该属性已被删除,因为 CKEditor 不允许。该过滤系统称为高级内容过滤器,您可以在此处阅读:
- http://ckeditor.com/blog/Upgrading-to-CKEditor-4.1 http://ckeditor.com/blog/Upgrading-to-CKEditor-4.1
- http://ckeditor.com/blog/CKEditor-4.1-发布 http://ckeditor.com/blog/CKEditor-4.1-Released
- 高级内容过滤器指南 http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter
简而言之 - 您需要配置编辑器以允许onclick
某些元素的属性。例如:
CKEDITOR.replace( 'editor1', {
extraAllowedContent: 'strong[onclick]'
} );
在这里阅读更多内容:config.extraAllowedContent http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-extraAllowedContent.
on*
CKEditor 中的属性
CKEditor 编码on*
加载内容时使用属性,这样它们就不会破坏编辑功能。例如,onmouseout
变成data-cke-pa-onmouseout
在编辑器内部,然后,当从编辑器获取数据时,该属性被解码。
没有为此的配置选项,因为它没有意义。
Note:当您在编辑器的可编辑元素内设置元素属性时,您应该将其设置为受保护的格式:
element.setAttribute( 'data-cke-pa-onclick', 'alert("blabla")' );
CKEditor 中的可点击元素
如果您想在编辑器中观察点击事件,那么这是正确的解决方案:
editor.on( 'contentDom', function() {
var element = editor.document.getById( 'foo' );
editor.editable().attachListener( element, 'click', function( evt ) {
// ...
// Get the event target (needed for events delegation).
evt.data.getTarget();
} );
} );
检查文档editor#contentDom event http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-contentDom这在这种情况下非常重要。