html - 一个 HTML 元素可以有多个 id 吗?

标签 html xhtml standards-compliance

我了解一个 id 在 HTML/XHTML 页面中必须是唯一的。

对于给定的元素,我可以为其分配多个 id 吗?

<div id="nested_element_123 task_123"></div>

我意识到我有一个简单的解决方案,只需使用一个类。我只是对以这种方式使用 id 感到好奇。

最佳答案

没有。来自 XHTML 1.0 Spec

In XML, fragment identifiers are of type ID, and there can only be a single attribute of type ID per element. Therefore, in XHTML 1.0 the id attribute is defined to be of type ID. In order to ensure that XHTML 1.0 documents are well-structured XML documents, XHTML 1.0 documents MUST use the id attribute when defining fragment identifiers on the elements listed above. See the HTML Compatibility Guidelines for information on ensuring such anchors are backward compatible when serving XHTML documents as media type text/html.

关于html - 一个 HTML 元素可以有多个 id 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/192048/

相关文章:

html - 如何仅使用 CSS3 获得四面八方的实体框阴影?

jquery - 使用jquery查找iframe中元素的高度

Java - XHTML 文档上的 SAX 解析器

php - 方法覆盖和严格的标准

ASP.net 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分

xml - 我应该学习 XML 1.0 还是 XML 1.1?

html - 从 SEO 的角度来看,将网站所有内容安排在 <ul><li> 中是否更好?

php - 单击后,div 内容在 jQuery 选项卡中消失了吗?

html - CSS :last-of-type is not working

javascript - 如何使div可点击?