开发者

Passing PHP GET into a jQuery function

I'm using a bit of jquery code which uses li items to select which tab is displayed. the "tabs" are just divs. This is the jQuery code:

$(document).ready(function() {

            //When page loads...
            $(".tab_content").hide(); //Hide all content
            $("ul.tabs li:first").addClass("active").show(); //Activate first tab
            $(".tab_content:first").show(); //Show first tab content

            //On Click Event
            $("ul.tabs li").c开发者_高级运维lick(function() {

                $("ul.tabs li").removeClass("active"); //Remove any "active" class
                $(this).addClass("active"); //Add "active" class to selected tab
                $(".tab_content").hide(); //Hide all tab content

                var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
                $(activeTab).fadeIn(); //Fade in the active ID content
                return false;
            });
        });

Where it says li:first and adds the active class to it, i'm trying to figure out how i can change which "tab" gets displayed first depending on a PHP GET result: <?php $tab = $_GET['tab']; ?>

"tab" will be a number 1,2,3 or 4. ie. tab 1, tab 2, etc...so how can i use this PHP variable with jQuery to choose which tab to make Active?

Thanks


What about something like this (assuming the 'tab' GET parameter is an index):

$("ul.tabs li:nth-child(<?= $_GET['tab'] ?>)").addClass("active").show(); //Activate first tab
$(".tab_content:nth-child(<?= $_GET['tab'] ?>)").show(); //Show first tab content
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜