确定当前打开的语义UI手风琴索引 [英] Determine currently opened Semantic UI accordion index

查看:159
本文介绍了确定当前打开的语义UI手风琴索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Trying to figure out how to determine currently open part of Semantic UI accordion (http://semantic-ui.com/modules/accordion.html):

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

This works for jQuery UI Accordion, does not work for Semantic UI:

$(#accordion").accordion('option','active');

$("#accordion").accordion('option','active');

也尝试了下面的代码,但始终返回"1":

Also tried below code, but always returns "1":

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

推荐答案

onChange回调中,this返回选定内容的容器作为jQuery对象.因此,您可以将其与通过内容选择器过滤的index()方法一起使用. 接下来尝试,它对我有用:

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"));
    }
});

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

这篇关于确定当前打开的语义UI手风琴索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆