问题
Trying to figure out how to determine currently open part of Semantic UI accordion (http://semantic-ui.com/modules/accordion.html):
This works for jQuery UI Accordion, does not work for Semantic UI:
$("#accordion").accordion('option','active');
Also tried below code, but always returns "1":
$('#selector').accordion({
onChange: function() {
alert("selected" + $('#selector').index() );
}
});
回答1:
Inside the onChange
callback, this
returns selected content' container as a jQuery object. So you can use it with the index()
method, filtered by content selector.
Try with next, it works for me:
$('.ui.accordion').accordion({
onChange: function () {
alert(this.index(".content"));
console.log(this.index(".content"));
}
});
Working example: http://jsfiddle.net/n8o1ps0t/
来源:https://stackoverflow.com/questions/25573315/determine-currently-opened-semantic-ui-accordion-index