繁体   English   中英

使用javascript将页面上所有经过aria扩展的内容更改为false

[英]Change all aria-expanded on a page to false with javascript

在解析HTML之前,我需要在页面上打开一些常见问题解答,因为答案的文本值是隐藏的,因此在解析页面HTML时显示为空。

当我在浏览器中使用下面的代码时,它将返回我所有链接,但不会将“ aria-expanded”属性更改为“ false”。

 $('a').each(function() { this.setAttribute('aria-expanded', 'false')});

我会尝试使用.attr()http://api.jquery.com/attr/

this.attr('aria-expanded','false')}

jQuery的方式应该工作:

$(function () {
     $('a').each(function() {
         $(this).attr('aria-expanded', 'false')
     });
});

我不认为this是指您想要的对象(标签)。 您可以尝试以下代码。

$('a').each(function(index, obj) { $(obj).attr('aria-expanded', 'false') });

setAttribute是本机JavaScript函数。 使用jatt的attr()。

$('a')。each(function(){this.attr('aria-expanded','false')});;

暂无
暂无

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

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