开发者

Programmatically change Tabs when using idTabs

I want to have the actual idtab button aswell as a link/button within the tab able to change tabs via JavaScript.

Is this possi开发者_运维问答ble if so how? Thanks


after looking through the examples again I have re-used the bulk of it and I have come up with the following

  function switchTab(ActiveTab) {
        var set = $('.idtabs').html();   

        $("a", set).removeClass("selected")
        .filter("[href='" + ActiveTab + "']", set).addClass("selected");

        $.each($("a", set), function (key, value) {
            $($(value).attr("href")).hide();
        });

        $(ActiveTab).show();}


I have just stumbled through your post after a google search. In case anyone else arrives here through the same way, I'll let an advice.

Instead of...

$("a", set).removeClass("selected")

...and...

$.each($("a", set), function (key, value) {

...one should use:

$("yourMenu#IdOrHTMLTag a")

It will prevent the code from calling jQuery's .hide() and .removeClass at all links of the page, which would raise an error.


You can achieve what you want just triggering the link's click event:

function switchTab(ActiveTab) {
    $("a[href'"+ActiveTab+"']").click();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜