在 Google PageSpeed Insights 报告中收到 [aria-*] attributes are not valid or misspelled
的错误意味着您的代码中使用的 ARIA 属性(例如 aria-role
)无效或拼写错误。ARIA(Accessible Rich Internet Applications)属性是用来增强网页对辅助技术(如屏幕阅读器)的可访问性的。如果这些属性不正确,可能会导致辅助技术无法正常工作。
错误分析
- 问题的属性:
aria-role="dialog"
这是无效的,因为aria-role
不是标准的 ARIA 属性,正确的属性是role="dialog"
。 - 出错的 HTML 元素:
html
<div class="e-contact-buttons e-contact-buttons-var-10 has-h-alignment-end has-v-align…" id="" data-document-id="14" aria-role="dialog">
修复方法
- 更改为有效的 ARIA 属性: 将
aria-role
修改为role
,如下:html<div class="e-contact-buttons e-contact-buttons-var-10 has-h-alignment-end has-v-align…" id="" data-document-id="14" role="dialog">
- 验证 ARIA 属性的拼写和用途: 检查是否有其他拼写错误的 ARIA 属性,例如:
aria-label
aria-hidden
aria-labelledby
- 使用 ARIA 验证工具: 在线验证工具,如 WAVE 或 axe Accessibility 插件,可以帮助检测网页中是否有其他无效的 ARIA 属性。
- 确保语义化 HTML: 除了正确使用 ARIA 属性,尽量使用语义化 HTML(如
<dialog>
或<button>
)来减少对 ARIA 的依赖。
修复这些问题后,重新运行 Google PageSpeed Insights 以验证修复是否成功。如果有其他疑问,可以随时联系我!