简体   繁体   English

Chrome execCommand('insertHTML')行为

[英]Chrome execCommand('insertHTML') behavior

While developing some kind of WYSIWYG-editor with not editable blocks, i found intresting behavior in Chrome (and Safari also): when you make an execCommand('insertHTML') in div with contenteditable="true" (or another element) - in work fine, like you expect. 在开发某种具有不可编辑的块的WYSIWYG编辑器时,我发现了Chrome(和Safari)中的有趣行为:当您在div使用contenteditable="true" (或另一个元素)创建execCommand('insertHTML')时-工作正常,如您所愿。 But if you try to execute it in nested div without " contenteditable " - browser remove all attributes, but add style according to css. 但是,如果您尝试在没有“ contenteditable ”的嵌套div执行它-浏览器将删除所有属性,而是根据CSS添加style

jsfiddle: http://jsfiddle.net/DXz9e/2/ jsfiddle: http : //jsfiddle.net/DXz9e/2/

Try to insert in inner and outer text. 尝试插入内部和外部文本。 And look at html-code. 并查看html代码。 I see in outer (with contenteditable): 我在外部看到(内容可编辑):

<span id="newInsertedNode" class="constructor-input-field" data-id="23">Some text</span>

And in inner: 在内部:

<span style="background-color: red; color: blue;">Some text</span>

I just want to say: "what a hell is going on?" 我只想说:“到底发生了什么?” Also it work fine in FF 在FF中也可以正常工作

一种解决方案是不使用Span元素(请参阅此处: https : //dev.ckeditor.com/ticket/9004 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM