我了解一个 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/