我在bootstrap中有以下列表
<i class="fa fa-plus rgh-i" data-toggle="collapse" data-target="#field-1"></i>
<i class="fa fa-plus rgh-i" data-toggle="collapse" data-target="#field-2"></i>
<i class="fa fa-plus rgh-i" data-toggle="collapse" data-target="#field-3"></i>我使用bootstrap切换div。
$( "i" ).on( "click", function() {
if(There are elements of that property aria-expanded="true")
{
hide previous item before you open the current one
}else{
//something
}
});我试着做一个jsdfiddle示例,但不幸的是我们做到了……我希望你已经理解了我想要做什么。
基本上..。
提前感谢!
发布于 2015-12-23 17:22:19
if(this.attr('aria-expanded') === "true"){
// hide previous item before you open the current one
}发布于 2015-12-23 17:20:10
您需要使用
选择具有指定属性且其值恰好等于特定值的元素
var areaexpandedtrue = $('[aria-expanded=true]');
if(areaexpandedtrue.length){
areaexpandedtrue.hide();
}发布于 2015-12-23 17:22:23
您也可以先获取值,然后再进行比较。
var value = $('#aria-expanded').val(); // jQuery func.
if (value =='true'){
//do some stuff
}
else{
//do some stuff
}https://stackoverflow.com/questions/34432222
复制相似问题