在下面的示例中,一个按钮被样式化成典型的“关闭”按钮,中间带有X。由于没有任何指示该按钮的目的是关闭对话框,因此使用aria-label属性向任何辅助技术提供标签。
<button aria-label="Close" onclick="myDialog.close()">X</button>
根据Bootstrap文档:
所以我想我也可以这样写:使用.sr-only可以将元素隐藏在除屏幕阅读器之外的所有设备上。
<button onclick="myDialog.close()"><span class="sr-only">Close</span>X</button>
在Bootstrap项目中,我应该如何选择首选项?
在Bootstrap项目中,我该如何选择偏好?
.sr-only
已被替换为<button aria-label="Close"><span aria-hidden="true">X</span></button>
。 - thdoanaria-hidden="true"
将防止屏幕阅读器读取该元素内的内容。因此,在@thdoan的示例中,屏幕阅读器只会读出“关闭”(而不是“关闭X”)。 - Matty J