Can I use an anchor ID starting with a number in HTML5?

陌路散爱 提交于 2020-02-03 09:38:43

问题


Can I use an anchor ID starting with a number in HTML5?

<a id="1" class="anchor"></a>

I was told this was a NO NO. But it seems to work fine in IE9, Firefox and Chrome. So, what gives?


回答1:


Yes, this is perfectly valid in HTML5.

3.2.3.1 The id attribute

The id attribute specifies its element's unique identifier (ID). [DOM]

The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.

Note: There are no other restrictions on what form an ID can take; in particular, IDs can consist of just digits, start with a digit, start with an underscore, consist of just punctuation, etc.

http://www.w3.org/TR/html5/dom.html#the-id-attribute (emphasis added)



来源:https://stackoverflow.com/questions/18222991/can-i-use-an-anchor-id-starting-with-a-number-in-html5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!