我是否真的需要从标签中删除第二个隐藏表单字段才能验证 HTML?
在以下代码中,我们在 w3c 验证器中收到错误“具有 for 属性的标签元素的任何输入后代必须具有与 for 属性相匹配的 ID 值”。 “标签元素最多可以包含一个输入、按钮、选择、文本区域或注册机后代。”这是应该被验证器忽略的东西(因为它看起来是正确的)还是应该更改它以安抚 w3c?请注意,这是 html5 文档类型。
<fieldset>
<label for="user_is_subscribed">
<input type="hidden" value="0" name="user[is_subscribed]">
<input type="checkbox" value="1" name="user[is_subscribed]" id="user_is_subscribed">
Newsletter Signup
</label>
<span class="checkLabel">We will never spam or give away your information</span>
</fieldset>
预先感谢!
We have the following code in which we are getting errors in the w3c validator for "Any input descendant of a label element with a for attribute must have an ID value that matches that for attribute." and "The label element may contain at most one input, button, select, textarea, or keygen descendant." Is this something that should just be ignored by the validator (as it is seeminlgly correct) or should it be changed to appease the w3c? Note this is html5 doctype.
<fieldset>
<label for="user_is_subscribed">
<input type="hidden" value="0" name="user[is_subscribed]">
<input type="checkbox" value="1" name="user[is_subscribed]" id="user_is_subscribed">
Newsletter Signup
</label>
<span class="checkLabel">We will never spam or give away your information</span>
</fieldset>
Thank in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标签最多应包含一个输入元素。将隐藏的输入移出标签。此外,当输入是标签的后代时,
for
属性是多余的。Labels should contain at most one input element. Move the hidden input out of the label. Also, when an input is a descendant of a label, the
for
attribute is superfluous.吗?
事实并非如此
是
不。它应该被更改,因为它是错误的,浏览器必须纠正错误才能找出标签与哪个元素关联。
该标签没有标记隐藏的输入,请将其移至其他地方。
No
It isn't
Yes
No. It should be changed because it is wrong, and browsers have to error correct to figure out which element the label is associated with.
The label isn't labeling the hidden input, move it elsewhere.