Html Chrome 63+ 抛出 [DOM] 错误,输入类型密码和非唯一 ID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47806187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Chrome 63+ throws [DOM] error with input type password and non-unique ids
提问by Arnab Ghosh
From Chrome 63, the following error is thrown:
从 Chrome 63 开始,抛出以下错误:
[DOM] Found 2 elements with non-unique id #a: (More info: https://goo.gl/9p2vKq)
[DOM] 发现 2 个具有非唯一 ID #a 的元素:(更多信息:https: //goo.gl/9p2vKq)
https://jsfiddle.net/arnabgh/jz186qxe/
https://jsfiddle.net/arnabgh/jz186qxe/
<input type="password">
<input id="a">
<input id="a">
Is there any special validation happening when input type password is used, starting from Chrome 63?
从 Chrome 63 开始,使用输入类型密码时是否会发生任何特殊验证?
回答by BoltClock
Yes, there is; that's why you're seeing that message. But I suspect that's not what you're really asking.
就在这里; 这就是您看到该消息的原因。但我怀疑这不是你真正要问的。
If your question is whyChrome has started displaying this message, my guess is that since passworded forms tend to transmit sensitive information (namely, a password), any errors in passworded forms should be brought to the developer's attention immediately. Greater care should be taken when designing and implementing passworded forms.
如果你的问题是,为什么Chrome浏览器已经开始显示这个消息,我的猜测是,由于需要密码的形式倾向于传送敏感信息(即密码),在需要密码形式中的任何错误,应立即提请开发者的关注。在设计和实施密码表单时应更加小心。
The document the error message links to (which I cannot assume that you've read since you've made no acknowledgement of it in your question) has a subsection on writing standards-compliant HTML, in which the unique ID rule is re-stated:
错误消息链接到的文档(我不能假设你已经阅读过,因为你没有在你的问题中承认它)有一个关于编写符合标准的 HTML 的小节,其中重新说明了唯一 ID 规则:
Follow HTML guidelines
Web browsers are designed with the HTML specification in mind, and going against it can lead to unexpected issues with your web page. This means:
Element
id
attributes should be unique: no two elements should have the sameid
.
遵循 HTML 指南
Web 浏览器的设计考虑到了 HTML 规范,违反它可能会导致您的网页出现意外问题。这意味着:
元素
id
属性应该是唯一的:没有两个元素应该具有相同的id
.
(Why that rule is the only one that's there is anyone's guess; it certainly looks like they intend to add more in the future, but it's still strange that they'd put out a document with just this one rule and call it good.)
(为什么这条规则是唯一一个有人猜测的规则;看起来他们当然打算在未来添加更多规则,但他们发布一份只有这条规则的文件并称其为好仍然很奇怪。)
There does not appear to be a way to disable this message, but since it doesn't prevent the page from working beyond how the duplicate IDs would have (and they don't either), if you're unable to correct the non-unique IDs yourself it's safe to ignore it.
似乎没有办法禁用此消息,但由于它不会阻止页面超出重复 ID 的工作方式(它们也不会),如果您无法更正非自己的唯一 ID 可以安全地忽略它。
回答by Ganesh Khadsan
Instead of [id]
try using [attr.id]
而不是[id]
尝试使用[attr.id]
This worked for me hope it helps.
这对我有用,希望它有所帮助。
回答by Krish
Instead of id='a'
use class='a'
with unique name, and then use with .a in or you can use unique id different then other field id like id='a'
and other field like id='b'
.
而不是与唯一名称一起id='a'
使用 class='a'
,然后与 .a 一起使用,或者您可以使用与其他字段 idid='a'
和其他字段不同的唯一 id id='b'
。