试图弄清楚如何确定语义UI手风琴的当前开放部分(http://semantic-ui.com/modules/accordion.html):
这适用于jQuery UI Accordion,不适用于语义UI:
$("#手风琴&#34)。手风琴('选项''有源&#39);
也尝试下面的代码,但总是返回" 1":
$('#selector').accordion({
onChange: function() {
alert("selected" + $('#selector').index() );
}
});
答案 0 :(得分:4)
在onChange
回调中,this
会返回所选内容'容器作为jQuery对象。因此,您可以将其与index()
方法一起使用,并按内容选择器进行过滤。
尝试下一步,它对我有用:
$('.ui.accordion').accordion({
onChange: function () {
alert(this.index(".content"));
console.log(this.index(".content"));
}
});
答案 1 :(得分:0)
这是我的功能,可以正常工作!
window.AcordionIndex = async (div) => {
var index = 0;
for (var i = 0; i < document.getElementById(div.replace("#", "")).children.length; i++) {
var clase = document.getElementById(div.replace("#", "")).children[i].className;
if (clase.indexOf('title') != -1) {
if (clase.indexOf('title active') != -1) {
break;
}
index++;
}
}
return index;
}