ID 在整个页面中必须是唯一的吗? [英] Does ID have to be unique in the whole page?

查看:31
本文介绍了ID 在整个页面中必须是唯一的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jQuery,我只是想知道,ID 是否必须在整个页面中始终唯一?类,我知道,可以重复多次,ID呢?

I am using jQuery and I am just wondering, does ID have to be always unique in the whole page? Class, I know, can be repeated as many times as you like, what about ID?

推荐答案

是的,它必须是唯一的.

Yes, it must be unique.

HTML4:

https://www.w3.org/TR/html4/struct/global.html#h-7.5.2

第 7.5.2 节:

id = 名称 [CS]此属性为元素分配名称.此名称在文档中必须是唯一的.

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

id 属性指定其元素的唯一标识符 (ID).这值在元素的主子树中的所有 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.

这篇关于ID 在整个页面中必须是唯一的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆