我有一个 angular2 应用程序,我将一些动态文本绑定到嵌套 DIV 的 ARIA-LABE1。但是当我使用 JAWS 阅读器在页面上定位 DIV 时,它没有阅读指定的文本。这是我试图阅读的文本 - attr.aria-label=“{{productDetails?.ProductName}} 的产品详细信息“
另外,如果我给这个 div 分配一个标题角色,它会读取动态文本,但不会在文本前加上“Product details for”前缀
<div [ngClass]="getDescClass()" class="prdDetails-div" aria-label="some text">
<div autofocus attr.aria-label="Product details for {{productDetails?.ProductName}}" class="productDetails-name" style="cursor:default!important" role="heading" >{{productDetails?.ProductName}} </div>
<div autofocus class="products-result-compare">
<!--{{getDescription(productDetails?.Description)}}-->
Small description
</div>
原文由 namrata 发布,翻译遵循 CC BY-SA 4.0 许可协议
您的描述缺乏细节或工作示例,因此我没有尝试提供解决方案,而是:
aria-label
不适用于<div>
也不是<span>
.A
<div>
和<span>
既不是地标也不是互动内容。aria-label
不会被屏幕阅读器读取(这是正确的)。在不知道用途的情况下,我有两个建议可能会有所帮助:
将
aria-label
直接放在控件上(知道它会覆盖控件的文本)。如果您希望 只有 屏幕阅读器用户才能看到,请使用一些屏幕外文本。
使用屏幕外技术:
CSS 可能看起来像这样(也考虑了 RTL 语言):
还有其他技术,但它们的价值取决于您的受众及其技术概况。
你对那些 --- 的使用
autofocus
<div>
让我很紧张。我希望您不要将它们用作交互式控件(如按钮)。理想情况下 永远不要使用div
作为交互式内容。