我是否真的需要从标签中删除第二个隐藏表单字段才能验证 HTML?

发布于 2024-11-03 02:48:18 字数 582 浏览 0 评论 0原文

在以下代码中,我们在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抠脚大汉 2024-11-10 02:48:18

标签最多应包含一个输入元素。将隐藏的输入移出标签。此外,当输入是标签的后代时,for 属性是多余的。

<fieldset>
  <input type="hidden" value="0" name="user[is_subscribed]">
  <label>
    <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>

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.

<fieldset>
  <input type="hidden" value="0" name="user[is_subscribed]">
  <label>
    <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>
陪你到最终 2024-11-10 02:48:18

这是验证器应该忽略的东西

吗?

(因为它看起来是正确的)

事实并非如此

或者应该改变

安抚w3c?

不。它应该被更改,因为它是错误的,浏览器必须纠正错误才能找出标签与哪个元素关联。

该标签没有标记隐藏的输入,请将其移至其他地方。

Is this something that should just be ignored by the validator

No

(as it is seeminlgly correct)

It isn't

or should it be changed

Yes

to appease the w3c?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文