我知道在 HTML4 中类和 id 不能以数字开头。
我在 HTML 5/php 中编码,我的许多 ID 和类中只有数字指向我的数据库中用于 jquery ajax 调用的主键。
我找不到 HTML5 类和 ID 规范的文档。在 HTML 5 中使用类名和 ID 名是否有效,例如,
class="122"
id="13213"
我已经通过 w3c 一致性检查器运行我的输出代码,一切正常,但我仍然想要确认!?
谢谢
最佳答案
我对此进行了彻底的研究并写下了我的发现: The id
attribute got more class
y in HTML5 强>。来自那篇文章:
HTML5 gets rid of the additional restrictions on the
id
attribute. The only requirements left — apart from being unique in the document — are that the value must contain at least one character (can’t be empty), and that it can’t contain any space characters.
要使用选择器 API 在 CSS 或 JavaScript 中定位以数字开头的类名或 ID,您应该 escape them .例如,以 id="404"
为目标元素, 你不能只使用 #404
— 你必须 escape it as follows :
#\34 04 {
background: pink;
}
关于css - HTML 5 类名和 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9210307/