两个HTML元素可以具有相同的ID,但可以在不同的类中吗? [英] Can two html elements have the same id but in different classes?

查看:287
本文介绍了两个HTML元素可以具有相同的ID,但可以在不同的类中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为一个现有的应用程序编写了一个javascript,其中有两种形式的 id 分别存在,每种形式中都有一个 div ,其ID为 validationSummary 。但是这些 div 属于不同的类。所以我的问题是这可能吗?请谁能解释我这是正确的吗?

I was writing a javascript for an existing application in which there are two forms with separate ids, and in each form there is a div which has the id "validationSummary". But these divs belong to different classes. So my question is can this be possible? Please anyone can explain me is this correct ?

这些是 div s:

<form id="foo" .....>
<div class="notice_bar validation-summary-errors error_message" id="validationSummary"></div>
</form>

<form id="bar" .....>
<div class="validation-summary-valid notice_bar affirmative_message" id="validationSummary"></div>
</form>

和类 notice_bar 是常见的

推荐答案

可能吗?是。
编码好吗?

Possible? Yes. Good coding? No.

来自 w3.org


ID和NAME令牌必须以字母开头([A-Za-z] ),可以是
,后跟任意数量的字母,数字([0-9]),连字符(-),
下划线( _),冒号(:)和句点(。)。

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

这篇关于两个HTML元素可以具有相同的ID,但可以在不同的类中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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