【问题标题】:wizard bootstrap return current tab向导引导程序返回当前选项卡
【发布时间】:2014-03-28 10:38:38
【问题描述】:

我在我的应用程序中实现了向导引导程序。

我想检索当前选项卡的索引以进行测试 显示或隐藏“下一个”“上一个”按钮


$('#rootwizard').bootstrapWizard({
    'nextSelector': '.button-next',
    'previousSelector': '.button-previous',
    onTabClick: function (tab, navigation, index) {
        var total = navigation.find('li').length;

        // here i want get the currecnt index of tab clicked 
        var current = index +1 ;
        alert();

        // set wizard title
        $('.step-title', $('#rootwizard')).text('Step ' + (index) + ' of ' + total);

        // set done steps
        jQuery('li', $('#rootwizard')).removeClass("done");
        var li_list = navigation.find('li');

        for (var i = 0; i < index; i++) {
             jQuery(li_list[i]).addClass("done");
        }
        if (current == 1) {
            $('#rootwizard').find('.button-previous').hide();
        } else {
            $('#rootwizard').find('.button-previous').show();
        }
        if (current >= 13) {
            $('#rootwizard').find('.button-next').hide();
            $('#rootwizard').find('.button-submit').show();
        } else {
            $('#rootwizard').find('.button-next').show();
            $('#rootwizard').find('.button-submit').hide();
        }
        App.scrollTo($('.page-title'));

HTML:

<ul class="nav nav-tabs">                               
    <li class=" active" id="dbt"><a href="#portlet_tab1" data-toggle="tab">aaa</a></li>
    <li class=""><a href="#portlet_tab2" data-toggle="tab">   bbb   </a></li>
    <li class=""><a href="#portlet_tab3" data-toggle="tab">   ccc   </a></li>
    <li class=""><a href="#portlet_tab4" data-toggle="tab">    dddd    </a></li>
</ul>

【问题讨论】:

    标签: jquery twitter-bootstrap wizard


    【解决方案1】:

    要显示来自 $(document).ready() 或代码中其他函数的索引:

    alert( $('#rootwizard').bootstrapWizard('currentIndex') );
    

    在您的情况下,在创建向导时,您在声明“onTabClick”函数时忘记了单引号。无论如何,我建议您改用“onTabShow”事件:

    $('#rootwizard').bootstrapWizard({
    'nextSelector': '.button-next',
    'previousSelector': '.button-previous',
    'onTabShow': function (tab, navigation, index) {
        var total = navigation.find('li').length;
    
        // here i want get the currecnt index of tab clicked 
        var current = index + 1 ;
        alert(current);
    
        // set wizard title --> CHANGED 'index' by 'current'
        $('.step-title', $('#rootwizard')).text('Step ' + (current) + ' of ' + total);
    
        // set done steps
        jQuery('li', $('#rootwizard')).removeClass("done");
        var li_list = navigation.find('li');
    
        for (var i = 0; i < index; i++) {
             jQuery(li_list[i]).addClass("done");
        }
        if (current == 1) {
            $('#rootwizard').find('.button-previous').hide();
        } else {
            $('#rootwizard').find('.button-previous').show();
        }
        if (current >= 13) {
            $('#rootwizard').find('.button-next').hide();
            $('#rootwizard').find('.button-submit').show();
        } else {
            $('#rootwizard').find('.button-next').show();
            $('#rootwizard').find('.button-submit').hide();
        }
        App.scrollTo($('.page-title'));
    

    我知道我有点晚了,但我希望它可以帮助其他人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-24
      相关资源
      最近更新 更多