Element.tagName总是大写吗? [英] Is Element.tagName always uppercase?

查看:50
本文介绍了Element.tagName总是大写吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于Element.tagName的MDN上阅读状态:

在标记为HTML文档的DOM树中的HTML元素上,tagName以大写形式返回元素名称.

On HTML elements in DOM trees flagged as HTML documents, tagName returns the element name in the uppercase form.

我的问题是:这值得信赖吗?IE(旧的和现代的)行为是否符合预期?这有可能改变吗?还是始终与 el.tagName.toLowerCase()一起使用会更好?

My question is: is this trustable? Does IE (old and modern) behave as expected? Is this likely to change? or is it better to always work with el.tagName.toLowerCase()?

推荐答案

您不必 toLowerCase 或其他任何东西,浏览器在这一点上都具有相同的功能(令人惊讶的是吗?).

You don't have to toLowerCase or whatever, browsers do hehave the same on this point (surprisingly huh?).

关于基本原理,我与一位在W3C标准方面非常专业的同事讨论过.如果他的意见是,使用大写的TAGNAME会更容易从用户内容中识别它们.这对我来说很有说服力.

About the rationale, once I had discussion with a colleague who's very professional on W3C standards. One if his opinion is that using uppercase TAGNAME would be much easier to recognize them out of user content. That's quite persuasive for me.

如@adjenks所说,如果文档用作 Content-Type:application/xhtml + xml <,则XHTML doctype返回大小写混合的tagName /em>.测试页: http://programming.enthuses.me/tag-node-case.php?doc = x

As @adjenks says, XHTML doctype returns mixed-case tagName if the document is served as Content-Type: application/xhtml+xml. Test page: http://programming.enthuses.me/tag-node-case.php?doc=x

从技术上讲,请阅读此规格以了解更多信息: http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-745549614

Technically, please read this spec for more info: http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-745549614

请注意,此(tagName)和DOM的所有操作一样,都是用XML保留大小写.无论源HTML文档中的大小写如何,HTML DOM均以规范的大写形式返回HTML元素的tagName.

Note that this (tagName) is case-preserving in XML, as are all of the operations of the DOM. The HTML DOM returns the tagName of an HTML element in the canonical uppercase form, regardless of the case in the source HTML document.

关于问问者的问题:这是可以信任的.HTML规范中不太可能发生重大更改.

As of asker's question: this is trustable. Breaking change is not likely to happen in HTML spec.

这篇关于Element.tagName总是大写吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆