当我与ckeditor合作时,有一个问题。我按下添加图像的图标,然后出现模态窗口,并将直接图像链接放在特殊字段中,此刻自动检测到宽度和高度,并为ex编写样式:
<img src='#some images direct link' style='width:SOME WIDTH;height:SOME HEIGHT'>
我可以禁用此自动功能吗?还是我每次都必须自己删除此样式?
你可以为配置编写一条规则,该规则将删除元素上的样式标签。
var editorRulesObject = {
elements: {
img: function( el ) {
if(el.attributes.style) {
el.attributes.style = '';
}
}
}
};
CKEDITOR.on('instanceReady', function( e ) {
// Ensures that any non-styled text, or text input without any tags will be correctly styled.
CKEDITOR.instances[e.editor.name].dataProcessor.dataFilter.addRules( editorRulesObject );
CKEDITOR.instances[e.editor.name].dataProcessor.htmlFilter.addRules( editorRulesObject );
});
哇!非常感谢你。它像一种魅力。;-)