确定当前打开的语义UI手风琴索引

时间:2014-08-29 17:29:44

标签: jquery accordion semantic-ui

试图弄清楚如何确定语义UI手风琴的当前开放部分(http://semantic-ui.com/modules/accordion.html):

这适用于jQuery UI Accordion,不适用于语义UI:

$("#手风琴&#34)。手风琴('选项''有源&#39);

也尝试下面的代码,但总是返回" 1":

    $('#selector').accordion({
        onChange: function() {  
            alert("selected" + $('#selector').index() );
        }
    });

2 个答案:

答案 0 :(得分:4)

onChange回调中,this会返回所选内容'容器作为jQuery对象。因此,您可以将其与index()方法一起使用,并按内容选择器进行过滤。 尝试下一步,它对我有用:

$('.ui.accordion').accordion({
    onChange: function () {
        alert(this.index(".content"));
        console.log(this.index(".content"));
    }
});

工作示例:http://jsfiddle.net/n8o1ps0t/

答案 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;
}