为什么我不能使用数值作为元素的 ID?
正在做一个项目,即将完成,刚刚整理 HTML,我发现你实际上不允许拥有一个只是数字的 ID -
< a>属性“id”具有无效值“567” 属性 ID 属于 ID 类型。如上所述,它应该以字母开头并且没有空格
Good <a id="567" href="/index.html">
Good <a id="n567" href="/index.html">
我可以浏览我的代码并添加一个字母,然后在我的 jQuery 中使用该值时将其删除,但它会弄乱我并不真正需要的。
我是否有理由不应该使用数字作为 ID?
Working on a project, nearly finished and just tidying up the HTML and I find out that you're not really allowed to have an ID that is just a number-
< a> attribute "id" has invalid value "567" The attribute ID is of type ID. As described above, it should begin with a letter and have no spaces
Good <a id="567" href="/index.html">
Good <a id="n567" href="/index.html">
I can go through my code and add a letter then strip it when the value is used in my jQuery but it would be messing around I don't really need.
Is there a reason I shouldn't be using numbers as ID's?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是规范所说的。
来自 HTML 4 规范:
好消息是 HTML 5 规范宽容:
That's just what the spec says.
From the HTML 4 specification:
The good news is that the HTML 5 specification is more lenient:
因为这就是 HTML4 规范的规定。
另一方面,HTML5 规范已删除此要求。
Because that's what the HTML4 spec dictates.
On the other hand, the HTML5 spec has removed this requirement.