我们应该使用

发布于 2024-09-02 11:37:31 字数 790 浏览 7 评论 0原文

我们应该为每个输入使用吗? ,即使是提交按钮,如果我们不想显示标签,也可以完全隐藏CSS。

或者不需要提交按钮的标签?

.hide {display:none}

<fieldset>
  <legend>Search</legend>
    <label for="Search">Search...</label>
      <input value="" id="Search" name="Search">
    <label for="Submit" class="hide">Submit</label>
      <input type="submit" value="Go!" name="submit" id="submit">
</fieldset>

或者我们应该这样使用(没有提交标签)

<fieldset>
  <legend>Search</legend>
    <label for="Search">Search...</label>
      <input value="" id="Search" name="Search">
      <input type="submit" value="Go!" name="submit" >
</fieldset>

Should we use <label> for every input? , even for submit button and keep hidden thorough css if we don't want to show label.

or no need of label for submit button?

.hide {display:none}

<fieldset>
  <legend>Search</legend>
    <label for="Search">Search...</label>
      <input value="" id="Search" name="Search">
    <label for="Submit" class="hide">Submit</label>
      <input type="submit" value="Go!" name="submit" id="submit">
</fieldset>

or we should use like this (no label for submit)

<fieldset>
  <legend>Search</legend>
    <label for="Search">Search...</label>
      <input value="" id="Search" name="Search">
      <input type="submit" value="Go!" name="submit" >
</fieldset>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

极致的悲 2024-09-09 11:37:31

不可以。不要对具有固有标签文本的元素(例如各种按钮)使用标签。 (注意:使用 value 属性伪造标签不算在内)。

请参阅有关该主题的 WCAG 部分的描述部分。

No. Don't use labels for elements which have intrinsic label text (e.g. all kinds of buttons). (Note: Faking a label with the value attribute doesn't count).

See the description section of the WCAG section on the subject.

橘和柠 2024-09-09 11:37:31

来自官方文档:

LABEL 元素可用于
将信息附加到控件。每个
LABEL 元素关联于
恰好是一个表单控件。

http://www.w3.org/TR/html4/ Interactive/forms.html#edef-LABEL

请注意,该术语是“可能是”,而不是“必须是”。但是,使用标签始终是一个好主意,因为出于可访问性原因以及对于在触摸屏设备上运行的浏览器来说,这非常方便。

From the official documentation:

The LABEL element may be used to
attach information to controls. Each
LABEL element is associated with
exactly one form control.

http://www.w3.org/TR/html4/interact/forms.html#edef-LABEL

Note that the term is "may be," not "must be." However, it is always a good idea to use a label because this turns out to be handy for accessibility reasons and for browsers running on touchscreen devices.

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