简体   繁体   English

jQuery选项卡-无法捕获选项卡单击

[英]jQuery Tabs - Unable to trap tab click

I am trying to trap the jQuery tab click event as follows: 我正在尝试捕获jQuery选项卡单击事件,如下所示:

$('#statisticsTab').tabs({
    activate: function (event, ui) {
        alert("In activate!");

        var $activeTab = $('#statisticsTab').tabs('option', 'active');
        if ($activeTab === 1) {
            alert("Tab 1 is active!");
        }
        else if ($activeTab === 2) {
            alert("Tab 2 is active!");
        }
        else if ($activeTab === 3) {
            alert("Tab 3 is active!");
        }
    }
});

The tab control itself works perfectly but none of the alerts in this code ever fire when I click on the various tabs. 选项卡控件本身可以完美运行,但是当我单击各种选项卡时,此代码中的任何警报都不会触发。 I'm using jQuery 1.10.2. 我正在使用jQuery 1.10.2。

Per request of the OP here's a slightly improved version and the fiddle that helped identify the problem: 根据OP的要求,这里有一个略微改进的版本,并且该小提琴有助于确定问题所在:

$('#statisticsTab').tabs({
activate: function (event, ui) {
    alert("In activate!");

    var $activeTab = ui.newTab.index();
    if ($activeTab === 1) {
        alert("Tab 1 is active!");
    }
    else if ($activeTab === 2) {
        alert("Tab 2 is active!");
    }
    else if ($activeTab === 3) {
        alert("Tab 3 is active!");
    }
}

}); });

FIDDLE 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM