简体   繁体   English

为什么HTML属性中的opener和closer的(')在document.documentElement.outerHTML中呈现为('')? 以及如何预防呢?

[英]Why the (') of opener and closer in HTML attribute is rendered as ('') in document.documentElement.outerHTML? and how to prevent it?

Why the single quote (') of opener and closer in HTML attribute is rendered as double quote ('') in document.documentElement.outerHTML? 为什么HTML属性中的opener和close的单引号(')在document.documentElement.outerHTML中呈现为双引号('')? and how to prevent it? 以及如何预防呢?

I have this element in my html page: 我的html页面中有此元素:

<div data-css="mo-cssclassvalueuseditems" class='{MO-CSS-CLASS value="UsedItems"}'>
</div>

When I tried to get the entire html via document.documentElement.outerHTML , as a result, it becomes like this: 结果,当我尝试通过document.documentElement.outerHTML获取整个html时,结果如下所示:

<div data-css="mo-cssclassvalueuseditems" class="{MO-CSS-CLASS value=&quot;UsedItems&quot;}">
</div>

For the &quot; 对于&quot; , it doesn't matter at all. ,一点都不重要。 But for the opener and closer of single-quotes ('), why it's rendered as double-quote ('') instead of single-quote (') ? 但是对于单引号(')的开头和结尾,为什么将其呈现为双引号('')而不是单引号(')?

Is there any solution to keep the quotes as it is? 有什么解决办法可以保持报价不变?

When the DOM is loaded, it's turned into DOM data structure that represents the logical relationships between all the elements and attributes. 加载DOM后,它变成了DOM数据结构,该数据结构表示所有元素和属性之间的逻辑关系。 It doesn't retain the source code. 它不保留源代码。 So it just has the information that the class attribute contains the value {MO-CSS-CLASS value="UsedItems"} . 因此,它仅具有class属性包含值{MO-CSS-CLASS value="UsedItems"} The fact that you used single or double quotes in the original HTML is lost in this translation to the DOM. 您在原始HTML中使用单引号或双引号的事实在此DOM转换中丢失了。 When an element is serialized by reading its innerHTMl or outerHTML property, attribute values are always surrounded by double quotes. 通过读取元素的innerHTMlouterHTML属性来序列化元素时,属性值始终用双引号引起来。

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

相关问题 有没有办法使用jQuery选择器来获取document.documentElement.outerHTML返回的相同字符串? - Is there a way to use the jQuery selector to get the same string as returned by document.documentElement.outerHTML? 如何将类属性应用于HTML字符串(未在文档上呈现) - How to apply a class attribute to an HTML string (not rendered on the document) 为什么 prop('outerHTML') 会剥离事件,我该如何阻止它? - Why does prop('outerHTML') strip events, and how can I prevent it? 无法设置 document.documentElement 的属性; - Can't set attribute of document.documentElement; document.documentElement.outerHTML.length 与 chrome 网络选项卡中的文档类型不相等 - document.documentElement.outerHTML.length is not equal with doc type in chrome network tab 如何找到document.DocumentElement.Client的Cordinates - How to find Cordinates of document.DocumentElement.Client 如何用 Jest 测试 document.documentElement? - How to test the document.documentElement with Jest? 为什么“ $(opener.document).ready()”不起作用? - why “$(opener.document).ready()” is not working? 是否始终定义document.documentElement并始终使用html元素? - Is document.documentElement always defined and always the html element? 将HTML元素添加为document.documentElement的直接子代有什么问题吗? - Is there anything wrong with adding an HTML element as a direct child of document.documentElement?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM