且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以在一个HTML文档中使用多个具有相同名称的ID :?

更新时间:2023-02-23 22:24:21

没有ID只能分配一次,因为它是单个元素的身份.您需要改用 class ,但我想知道为什么需要分配相同的ID?如果您将相同的ID分配给多个元素,并使用javascript等进行操作,则只有具有相同ID的最后一个元素才会被忽略,而忽略了所有先前的元素....

No id can be assigned only once since it is an identity for just a single element. You need to use class instead but i wonder why you need to assign same ids? If you assign same ids to more than one element, and use javascript, etc to manipulate it, then only last element with same id will be taken care of ignoring all previous elements....

有关更多信息,请参见:

For more information, please see:

ID与CLASS