我正在尝试从CKEditor中的图像更改HTML输出,但在迭代从数据处理器函数返回的元素时遇到了问题。
编辑器中的HTML:
<p>Test</p>
<p><img alt="" class="align-left" height="170" src="http://example.local/assets/img/uploads/photo.jpg" width="161" /> some text</p>
数据处理器:
htmlFilter.addRules( {
elements : {
$ : function( element ) {
console.log(element.children);
element.children.forEach(function(ele) {
console.log(ele);
});
}
}
});
我想简单地使用像element.name == 'img'
这样的东西来查找图像标记,但是只解析了p
-tags。当我登录element.children
时,我在第二段中看到img
:
但是,当我使用element.children.forEach(function(ele) { console.log(ele); })
迭代element.children
时,我得到的是这个标记,而不是img
标记,span
包含img
有人知道发生了什么吗?如何访问镜像标签?
我使用的是增强图片插件btw,尽管我不认为这有什么关系。
发布于 2018-02-02 19:47:49
请使用img
而不是$
。无论何时切换到源模式或从编辑器中获取数据,您都会通过该代码获得图像。
var editor = CKEDITOR.replace( 'editor1', {
on: {
pluginsLoaded: function( evt ) {
evt.editor.dataProcessor.htmlFilter.addRules( {
elements: {
img: function( el ) {
console.log( el );
}
}
} );
}
}
});
https://stackoverflow.com/questions/48498138
复制相似问题