我找到了一个解决方案。
这会关闭过滤,虽然可以工作,但不是一个好主意...
config.allowedContent = true
使用内容字符串来处理id等属性是有效的,但对于类和样式属性不行,因为需要用()和{}进行类和样式过滤。
因此,我建议允许在编辑器中使用任何类:
config.extraAllowedContent = '*(*)'
这允许任何类别和任何内联样式。
config.extraAllowedContent = '*(*);*{*}'
只允许任何标签使用 class="asdf1" 和 class="asdf2":
config.extraAllowedContent = '*(asdf1,asdf2)';
所以您必须指定类名。
仅允许在 p 标签中使用 class="asdf":
config.extraAllowedContent = 'p(asdf)';
允许任何标签使用id属性:
config.extraAllowedContent = '*[id]'
等等等等
为了允许样式标签(<style type="text/css">...</style>):
config.extraAllowedContent = 'style'
再来稍微复杂一些:
config.extraAllowedContent = 'span;ul;li;table;td;style;*[id];*(*);*{*}'
希望这是一个更好的解决方案...