how to select a particular tab from other page using anchor tag in JQuery..?

后端 未结 3 1182
刺人心
刺人心 2021-01-19 07:30

I wonder if we can able to select a particular tab in a JQuery tab system from another page..?

For example I have a 4 menus that is Home | About | Services | Contac

3条回答
  •  误落风尘
    2021-01-19 08:18

    (I've made a 'fiddle' on jsFiddle so you can test this answer.)

    You code was almost correct; it seems that a few HTML errors may have been the cause. Assuming our HTML looks like:

    
    
    1
    2
    3
    4
    5

    ... our JavaScript should be:

    $(document).ready(function() {
        //When page loads, hide all content 
        $(".tab_content").hide();
        $(".tab_content:first").show(); //Show first tab content
        $("#tabs li:first").addClass("active").show(); //Activate first tab
        //On Click Event
        $("#tabs a").click(function() {
    
            //Remove any "active" class
            $("#tabs .active").removeClass("active");
    
            //Add "active" class to selected tab
            $(this).parent().addClass("active");
    
            // Hide all tab content
            $(".tab_content").hide();
    
            //Find the href attribute value to identify the active tab + content
            var a = $(this).attr("href");
    
            //Fade in the active ID content
            $(a).fadeIn();
    
            return false;
        });
    });
    

提交回复
热议问题