我觉得奇怪的是,当我们执行 element.tagName
时,所有浏览器(Chrome/FF/IE/Safari/Opera)始终以大写形式返回标签名称。
是否真的有官方的 w3c 声明声明用户代理实际上必须以大写形式返回标签名称?
最佳答案
您正在寻找 DOM Level-2 :
tagName
of typeDOMString
, readonly
The name of the element.
[...]
Note that this is case-preserving in XML, as are all of the operations of the DOM. The HTML DOM returns thetagName
of an HTML element in the canonical uppercase form, regardless of the case in the source HTML document.
因此 e.tagName
对于 HTML 应该总是是大写的,但是对于 XML 来说大小写会与源文档相匹配。
关于javascript - 实际上是否有官方的 w3c 声明声明用户代理实际上必须返回 uppcase 元素的标签名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6894561/