[英]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="UsedItems"}">
</div>
For the "
对于
"
, 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. 通过读取元素的
innerHTMl
或outerHTML
属性来序列化元素时,属性值始终用双引号引起来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.