jQuery UI:手风琴回调 [英] JQuery UI: Accordion callbacks

查看:70
本文介绍了jQuery UI:手风琴回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的javascript仅在打开手风琴的某个部分时执行回调,截至目前,由于我仅使用click函数,因此当我打开或关闭一个部分时它才执行回调.有什么方法可以修改我现有的点击功能,使其仅在给定的部分被激活时运行?

I need my javascript to only do the callback when I OPEN a section on the accordion, as of right now it does a callback when I open OR close a section because I'm only using a click function. Is there a way I can modify my existing click function to only run when the given section is activated?

我当前的点击功能:

$("a#mimetypes").click(function() {
    $("span#mimetypesthrobber").loading(true, { max: 1500 })
    $.getJSON("../mimetypes", function(data) {
        //callback
    });
});

谢谢!

我已经在手风琴的另一部分进行了尝试,但无法正常工作:

I already tried this with another part of the accordion and it wasn't working properly:

$('.ui-accordion').bind('accordionchange', function(event, ui) {
if (ui.newHeader == "Encoders") {
EncodersGet();
}
});

推荐答案

,您可以使用"

$('.ui-accordion').bind('accordionchange', function(event, ui) {
  ui.newHeader // jQuery object, activated header
  ui.oldHeader // jQuery object, previous header
  ui.newContent // jQuery object, activated content
  ui.oldContent // jQuery object, previous content
});

例如访问"newHeadert"并进行处理

and access the "newHeadert" for example and do your processing

编辑

根据新信息{collapsible:true,active:false}

according to the new info {collapsible: true, active: false}

$(document).ready(function() {
            var $acc = $('#accordion').accordion({ collapsible: true,
                   active : false ,
                   change : function (event, ui)
                   {
                                var index = $acc.accordion( "option", "active");
                    if( index === false){
                                 // all are close
                                }
                                else{
                                 // 0-based index of the open section
                                }

                   }
            });
        });

活动的选项"将返回打开部分的索引,如果所有部分都关闭,则返回"false"

the "option, active" would return you the index of the open section or "false" if all sections are closed

这篇关于jQuery UI:手风琴回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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