Fieldset和legend元素用于组合相关的表单控件。对于“常规”表单,例如“您的详细信息”fieldset,其中包含名字、姓氏等文本输入字段,这很容易理解和应用。
然而,在应用程序的列表页面上,用户选择带有关联复选框的表格行以执行所选行的批量操作时,是否应该使用fieldset和legend元素呢?
例如:
<form>
<fieldset>
<legend>Users</legend>
<table>
<thead>
<tr>
<th></th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="SelectedItem" value="Anna" /></td>
<td>Anna</td>
</tr>
<tr>
<td><input type="checkbox" name="SelectedItem" value="Chris" /></td>
<td>Chris</td>
</tr>
</tbody>
</table>
<label for="ListAction">Bulk action</label>
<select id="ListAction" name="ListAction">
<option value="Nothing" selected="selected">Select action</option>
<option value="Delete">Delete</option>
<option value="Suspend">Suspend</option>
</select>
<input type="submit" value="Go" name="BulkActionGo" />
</fieldset>
</form>
https://www.w3.org/TR/WCAG20-TECHS/H71.html指出:“对于相关的单选按钮和复选框,分组控件是最重要的。当一组单选按钮或复选框都提交给同一个命名字段时,它们就是相关的。”
尽管上述示例符合这种情况,但是fieldset / legend似乎并不适用于此用例,因为该用例可能包含大量表格数据 - 以及无关的分页控件 - 而不仅仅是一组简单的表单控件。