【发布时间】:2017-10-07 00:32:48
【问题描述】:
我的搜索表单的当前 HTML 如下所示:
<form action=“/search/” method="post">
<input onclick="this.value='';" type="text" name="searchquery" id="searchbox" value="Search this site” class="swap_value" />
<input type="image" src=“/images/searchbutton.gif" id="searchbutton" alt="" />
</form>
我想让搜索表单可访问。据我了解 W3.org 的可访问性:https://www.w3.org/WAI/tutorials/forms/labels/ 和 a11ymatters.com:http://www.a11ymatters.com/pattern/accessible-search/,我需要添加一个不会在视觉上显示的标签,并对搜索按钮进行描述,如下所示:
<form action=“#” method="post">
<label class=“search-label” for=“search”>Search this site:</label>
<input onclick="this.value='';" type="text" name="searchquery" id="searchbox" value="Search this site” class="swap_value" />
<input type="image" src=“/searchbutton.gif" id="searchbutton" alt=“Search Button“ />
</form>
使用添加的 CSS:
.search-label {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
W3.org 文章说您可以使用 label、aria-label 或 aria-labelledby 来标识表单控件,但它没有说明哪种方法是最佳实践。有谁知道哪个是首选/最佳实践? alt 标签是否足以识别我的搜索按钮,还是也需要标签?
非常感谢!
【问题讨论】:
-
只是一个快速评论,标签应该与您示例中的输入文本框“搜索框”相关联,而不是搜索按钮。
标签: html forms search accessibility