获得咏叹调扩展的价值 [英] Get aria-expanded value
本文介绍了获得咏叹调扩展的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找不到从DOM中获得咏叹调扩展价值的方法.
I didn't find a way to get aria-expanded value from DOM.
<a class="accordion-toggle collapsed" href="#collapse-One" data-parent="#accordion-1" data-toggle="collapse" aria-expanded="false">
<i class="fa fa-search-plus"></i>
test
</a>
我要测试它是否为true
,然后可以将<i>
类更改为fa-search-minus
.我尝试了这个,但是我总是得到一个未定义的值:
I want to test if it's true
then I can change <i>
class to fa-search-minus
. I tried this but I always get an undefined value:
console.log($(this).find('a.aria-expanded').val());
推荐答案
aria-expanded
是元素上的属性,而不是类,因此选择器不正确.其次,您应该使用attr()
函数来获取该属性的值. val()
旨在从与表单相关的元素(例如input
和textarea
)中检索value
属性.试试这个:
aria-expanded
is an attribute on the element, not a class, so the selector is incorrect. Secondly, you should use the attr()
function to get the value of that attribute. val()
is intended to retrieve the value
attribute from form related elements, such as input
and textarea
. Try this:
console.log($(this).find('a[aria-expanded]').attr('aria-expanded'));
这篇关于获得咏叹调扩展的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文