css - HTML 5 类名和 ID

标签 css html

我知道在 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/

相关文章:

css - 我的 JS Accordion 表现得很愚蠢——它到处乱跳

html - 跨度末尾的空格会影响后伪元素的绝对定位

jquery - css z-index 指针事件

php - mySQL、PHP、带有可排序列的 HTML 表 - 但某些列值存在问题

javascript - 在 Windows Phone 8 上的 IE10 中查找屏幕分辨率

jquery - 如何为非设计人员设计一个在客户端充分利用 JQuery 的网站?

javascript - 滚动堆叠菜单

jquery - 如何使用 jQuery 以悬停效果定位特定父级的子级?

html - 我可以使用哪种示例 url 会立即导致请求失败?

javascript - 水平滚动 div 的内容被剪切