1

首先请访问我的小提琴:http: //jsfiddle.net/VsqQ3/

目前,前三个选项卡(tab 1, tab 2, tab 3)默认显示,当我单击next>:tab 4tab 5tab 6正在显示。

我想要什么:我想默认显示tab 4, tab 5tab 6我怎么能得到那个?

$(".wrapper #tab1,.wrapper #tab2").tabs({active: 0}).tabs({
            collapsible: false,
            hide: {
                    effect: "slideUp",
                    duration: 20
            },
            show: {
                    effect: "slideDown",
                    duration: 200
            }
    });

    var all = $('.wrapper .main').addClass("passiv");
    var prev = $('.wrapper .prev');
    var next = $('.wrapper .next');
    var tab_count = all.length-1;
    var currentContainer = -1;

    prev.click(function(e) {
        e.preventDefault();   

        if (currentContainer != 0) {
            currentContainer -= 1;
            ctrlcontent(currentContainer);
        }
    });

    next.click(function(e) {
        e.preventDefault();

        if (currentContainer < tab_count) {
            currentContainer += 1;
            ctrlcontent(currentContainer);
        }
    }).trigger('click');

    function ctrlcontent(index_to_show) {
       all.removeClass("active").addClass("passiv");
       all.eq(index_to_show).removeClass("passiv").addClass("active");

       if (index_to_show == 0) prev.hide();
       if (index_to_show == tab_count) next.hide();
       if (index_to_show > 0) prev.show();
       if (index_to_show < tab_count) next.show();
    }


    $(function() {
            $( ".wrapper .inner" ).buttonset();
    });
4

2 回答 2

1

如果您查找以下行:

    var currentContainer = -1;

你可以把它改成

    var currentContainer = Math.floor(all.length / 2) - 1; // -1 needed as your indexing seems to start at -1 rather than 0

它应该总是在中间容器上启动它

http://jsfiddle.net/VsqQ3/5/

于 2013-05-21T09:09:33.257 回答
1

只需添加 next.click();到您的代码:)

jsFiddle

next.click().click();最后3个标签:)

jsFiddle

于 2013-05-21T09:10:50.963 回答