简体   繁体   English

触发器选项卡激活功能-jQuery UI选项卡

[英]Trigger Tab activate function - JQuery UI Tabs

I run into problem. 我遇到了问题。

HTML snippet looks like this HTML代码段如下所示

<div id="mainTab">
    <ul>
        <li><a href='#tabs-1'>TabGroup1</a></li>
        <li><a href='#tabs-2'>TabGroup2</a></li>            
    </ul>
    <div id='tabs-1'>
        <a onclick="showSubTab1Tab2();">showSubTab1Tab2</a>
        <a onclick="showSubTab2Tab2();>showSubTab2Tab2</a>
    </div>
    <div id='tabs-2'>
        <!-- First Sub Tab -->
        <div id="subTab1">
            <ul>
                <li><a href='#tabs-3'>TabGroup3</a></li>
                <li><a href='#tabs-4'>TabGroup4</a></li>            
            </ul>
            <div id='tabs-3'>

            </div>
            <div id='tabs-4'>

            </div>
        </div>
        <!-- Second Sub Tab -->
        <div id="subTab2">
            <ul>
                <li><a href='#tabs-5'>TabGroup5</a></li>
                <li><a href='#tabs-6'>TabGroup6</a></li>            
            </ul>
            <div id='tabs-5'>

            </div>
            <div id='tabs-6'>

            </div>
        </div>
    </div>
</div>

And javascript look like this. 和javascript看起来像这样。 I am using JQuery UI 1.10.3 我正在使用JQuery UI 1.10.3

$("#mainTab").tabs();

$( "#subTab1" ).tabs({
    activate: function( event, ui ) {
        // Update Some Logs
    }
});

$( "#subTab2" ).tabs({
    activate: function( event, ui ) {
        // Update Some Logs
    }
});

function showSubTab1Tab2() {
    $("#mainTab").tabs( "option", "active", 1);
    $( "#subTab1" ).tabs( "option", "active", 1);
}

function showSubTab2Tab2() {
    $("#mainTab").tabs( "option", "active", 1);
    $( "#subTab2" ).tabs( "option", "active", 1);
}

If User click on "showSubTab2Tab2". 如果用户单击“ showSubTab2Tab2”。 I changed the main tab. 我更改了主标签。 Take the user to second tab. 将用户带到第二个选项卡。 and then activate the second tab of subTab2 and If the tab is not previously active This will activate the second tab and fires activate event 然后激活subTab2的第二个选项卡,如果该选项卡先前未激活,则将激活第二个选项卡并触发激活事件

Now here is the problem. 现在这是问题所在。 If user do that twice then on second time the activate event is not fired. 如果用户两次执行此操作,则第二次未激活事件。 I need that event to log/populate some code on frontent. 我需要该事件来记录/填充前端代码。

I can't do that in my function. 我不能在我的职能中做到这一点。

and if you try to check the status previously in showSubTab1Tab2() 并且如果您尝试检查以前在showSubTab1Tab2()的状态

http://jsfiddle.net/S4nua/1/ http://jsfiddle.net/S4nua/1/

Try this instead of your "tabs" code. 试试这个代替您的“标签”代码。 It will fire every time the tab is shown: 每次显示标签时都会触发:

$('a[href="#subTab2"]').on('shown', function () {
        ---- your code here ----
  });

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

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