我正在使用 jQuery,我只是想知道,ID 在整个页面中是否必须始终是唯一的?类,我知道,可以重复多次,那么 ID 呢?
最佳答案
是的,它必须是唯一的。
HTML4:
https://www.w3.org/TR/html4/struct/global.html#h-7.5.2
第 7.5.2 节:
id = name [CS] This attribute assigns a name to an element. This name must be unique in a document.
HTML5:
https://www.w3.org/TR/html5/dom.html#element-attrdef-global-id
The id attribute specifies its element's unique identifier (ID). The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.
关于html - HTML元素的id属性在整个页面中必须是唯一的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49925058/