简体   繁体   English

加载 DOM 后添加的 WAI-ARIA 属性

[英]WAI-ARIA attributes added after DOM is loaded

I have to improve website under web accessibility.我必须在 web 可访问性下改进网站。 I am adding aria attributes directly in html where possible in Drupal, but there are things that I can not add in html, like carousels and slideshows, so is it okay to add aria attributes to an element after document is loaded.我在 html 中直接在 Drupal 中添加 aria 属性,但是有些东西我不能在 html 中添加,比如轮播和幻灯片,所以可以在加载文档属性后添加元素。 like喜欢

$(document).ready(function(){
  $(".item").attr("aria-label", "My Label");
});

Yes it is acceptable to do this if you have no other options.是的,如果您没有其他选择,这样做是可以接受的。

However be aware that this isn't a 100% fool-proof way of doing things with certain screen readers (it should work correctly in the latest versions of NVDA, VoiceOver and JAWs).但是请注意,这并不是使用某些屏幕阅读器的 100% 万无一失的方式(它应该在最新版本的 NVDA、VoiceOver 和 JAW 中正常工作)。

Some older screen readers will build the accessibility tree on document load so it would be prudent (if somewhat of a bad practice but the best workaround I can think of) to do it via vanilla JS as an inline JS block in the footer.一些较旧的屏幕阅读器将在文档加载时构建可访问性树,因此通过 vanilla JS 作为页脚中的内联 JS 块来实现是谨慎的(如果有点不好,但我能想到的最佳解决方法)。

This may not be possible given your current setup, if that is the case then the way you suggested is acceptable and the best you will be able to achieve in a reasonable timescale.鉴于您当前的设置,这可能是不可能的,如果是这种情况,那么您建议的方式是可以接受的,并且您将能够在合理的时间范围内达到最佳效果。

If you really want to fix it (and you should.) - have you thought about replacing the offending plugins / libraries (or extending / editing the libraries / plugins) to add the required elements when the HTML is generated.如果你真的想修复它(你应该。) - 你是否考虑过在生成 HTML 时替换有问题的插件/库(或扩展/编辑库/插件)以添加所需的元素。 That is how I would handle this.我就是这样处理的。

Yes, using:是的,使用:

$(document).ready( ()=> {
...
});

will apply particular attributes once your web page is fully loaded.一旦您的 web 页面完全加载,将应用特定属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM