请根据 W3C.org Web Accessibility Initiative 的网站检查以下优先顺序:
<label for="reference-id for labelled form-element" class="visuallyhidden">
<form-element aria-label="label for the form-element">
<form-element aria-labelledby="reference-id's for label-element">
<form-element aria-describedby="reference-id's for descriptive-element">
<form-element title="description for the element">
所有屏幕阅读器均不建议也不支持仅使用标题标签。实际上,许多屏幕阅读器将无法聚焦标题标签,从而无法通过键盘控制访问它,从而跳过阅读内容。
标签控件
https://www.w3.org/WAI/tutorials/forms/labels/
方法四:使用title属性
title 属性也可以用来识别表单控件。这种方法通常不太可靠并且不推荐,因为某些屏幕阅读器和辅助技术不会将标题属性解释为标签元素的替代品,可能是因为标题属性通常用于提供非必要信息。当鼠标悬停在表单域上时,title 属性的信息作为工具提示显示给视觉用户。
恕我直言,您不应该使用 aria-labelledby 单独标记按钮,因为实际上按钮元素已经显示“(图标被 CSS 隐藏!?)显示原始结果”,恕我直言,这已经足够理解了。
在以下链接中扩展 WAI 的 aria- describeby 基本示例可能会更好,为您的示例生成以下内容:
使用 aria- describeby 属性为用户界面控件提供描述性标签
https://www.w3.org/WAI/WCAG21/Techniques/aria/ARIA1
<button
id="show-raw-result"
class="btn btn-default btn-sm btn-twigfiddle"
title="Result was not easily readable so it has been automatically cleaned up, use this button to see the result raw"
aria-describedby="description-raw-result"
<span class="glyphicon glyphicon-asterisk"></span> Show raw result
</button>
...
<div id="description-raw-result">Result was not easily readable so it has been automatically cleaned up, use this button to see the result raw</div>
请注意,在示例 4 下还有一个涉及工具提示的更详细的示例,但它也需要您实现 JavaScript 的 showTooltip() 函数。
因此,您可以决定是继续使用工具提示的 title 属性,还是更喜欢使用以下两个事件处理程序将描述性文本显示为工具提示:
onmouseover="tooltipShow(event, this, 'description-raw-result');"
onfocus="tooltipShow(event, this, 'description-raw-result');"
不幸的是,据我所知,没有用于显示工具提示的简写方式,可以使用引用,就像 aria- describeby 属性一样。