如果一个设置了几个html标签的id属性值,那么会发生什么? [英] what happens if one set id attribute values of several html tags, the same string?
问题描述
正如我听说每个html标签(如果有的话)的id属性必须是唯一的,现在我想知道如果它是不是这种情况??
可能导致什么样的错误?
不同的浏览器对这个问题有不同的反应吗?
的JavaScript和jquery代码使用重复的id在两个标签上运行或者什么? div>
重复ID可以有各种不同的效果。您所遇到的将取决于您尝试访问它们的方法(也可能从浏览器到浏览器)。
- 您会影响所有人
- 您会影响第一张
- 您将影响最后一张
- 你会得到一个集合而不是一个元素,尝试把它当作一个元素来对待并且得到一个错误。
重复的id不是允许使用HTML。不要为自己制造麻烦。
。使用用于组和id的类来获得唯一标识符。
I recently saw a html page, that i thought the id of several html tags was the same, then I realized the ids are unique but it raises the question that what could have happened if the page actually used several tags
As i have heard id attribute of every html tag(if it has one) must be unique,
now i wonder what happens if it is not the case??
what possible errors can it cause?
does different browsers show different reactions for this issue?
does javascript and jquery codes that use duplicated ids run on both tags or what?
Duplicate ids can have various different effects. Which you experience will depend on the method you use to try to access them (and possibly also from browser to browser).
- You'll affect all of them
- You'll affect the first one
- You'll affect the last one
- You'll get a collection instead of an element, try to treat it like an element and get an error
Duplicate ids are not allowed in HTML. Don't make trouble for yourself. Use classes for groups and ids for unique identifiers.
这篇关于如果一个设置了几个html标签的id属性值,那么会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!