两个HTML元素可以具有相同的ID,但可以在不同的类中吗?

编程入门 行业动态 更新时间:2024-10-07 06:48:57
本文介绍了两个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 :

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,但可以在不同的类中吗?

本文发布于:2023-08-03 14:37:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1287715.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类中   元素   两个   HTML   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!