如何将“aria-labelledby”属性添加到<asp:CheckBoxList>内的复选框?

问题描述 投票:0回答:1

我需要更新

<asp:CheckBoxList>
内的构面复选框,以使
aria-labelledby
属性更易于用户访问。但是,我找不到直接定位复选框部分的方法。

如果我在控制器中像这样添加它们:

//checkboxListItem is the object representing the checkbox/label collection
checkboxListItem.Attributes.Add("aria-labelledby", ${uniqueLabelOfTheCheckBox.ID}_{indexOfFacet});
checkBoxList.Items.Add(checkboxListItem); //adds the object to the ASP checkboxList

然后标记会将

aria-labelledby
包装在
<span>
标签中,这是不正确的。如何以及在哪里可以将 ARIA 标签添加到复选框本身?

c# asp.net webforms
1个回答
0
投票

在这种情况下,您不必使用 aria-labelledby,因为它的功能是通过使用

label for=""
自动提供的。所以由asp.net生成的html代码就可以了。

来自文档:

幸运的是,带有 type="checkbox" 的 HTML 可以与原生 .如果可行,请使用以下方法:

<label for="tac">
 <input id="tac" type="checkbox" name="terms-and-conditions" />
    I agree to the Terms and Conditions.
</label>
<p><a href="tac.html">Read our Terms and Conditions</a>.</p>

有关更多详细信息,请阅读此处:https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby

© www.soinside.com 2019 - 2024. All rights reserved.