Chrome 63 +使用输入类型的密码和非唯一的ID引发[DOM]错误 [英] Chrome 63+ throws [DOM] error with input type password and non-unique ids

查看:1091
本文介绍了Chrome 63 +使用输入类型的密码和非唯一的ID引发[DOM]错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Chrome 63开始,会抛出以下错误:


[DOM]找到2个包含非唯一ID的元素#a:


https:/ /jsfiddle.net/arnabgh/jz186qxe/

 < input type =password> 
< input id =a>
< input id =a>

从Chrome 63开始使用输入类型密码时是否有任何特殊验证发生?

解决方案

是的,这就是为什么你看到这个消息。但我怀疑这不是你真正要求的。



如果你的问题是为什么 Chrome已经开始显示这条消息,我的猜测是由于密码形式倾向于传输敏感信息(即密码),因此任何错误形式的错误都应立即引起开发人员的注意。实际上,实际显示的信息包含指向更多信息:的链接,该链接位于专门用于密码表单的设计文档,Chromium团队已将其放在一起专门解决这个问题。出于某种原因,您从引用的信息中省略了此链接,并且在您的问题中未对其进行确认,所以我不能认为您已阅读过该链接。话虽如此,设计文档本身有一个关于编写符合标准的HTML的小节,其中重申了唯一ID规则:


遵循HTML准则



Web浏览器的设计符合HTML规范,违背它可能会导致您的网页出现意外问题。这意味着:

元素 id 属性应该是唯一的:没有两个元素应该具有相同的 id


(为什么这个规则是唯一有人猜测的;就像他们打算在未来增加更多的东西一样,但是他们会用这条规则发布一个文档并称它为好,这仍然很奇怪。)



似乎不是禁用此消息的一种方式,但由于它不会阻止页面超出重复ID的使用范围(而且它们也不会),所以如果您无法更正非唯一ID你自己可以忽略它。


From Chrome 63, the following error is thrown:

[DOM] Found 2 elements with non-unique id #a:

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?

解决方案

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 why Chrome 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.

In fact, the message that's actually displayed contains a link pointing to "More info:" in a design document dedicated to passworded forms that the Chromium team has put together specifically to address this. For some reason you've omitted this link from the quoted message and made no acknowledgement of it in your question, so I cannot assume that you've read it. Having said that, the design document itself has a subsection on writing standards-compliant HTML, in which the unique ID rule is re-stated:

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 same 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.

这篇关于Chrome 63 +使用输入类型的密码和非唯一的ID引发[DOM]错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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