jQuery如何显示带有其他页面链接的特定选项卡 [英] jquery how to show specific tab with link from another page

查看:95
本文介绍了jQuery如何显示带有其他页面链接的特定选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示带有其他页面链接的特定标签页

how to show specific tab with link from another page

<a href="index.php?page=home#tab2">Home</a>

这是JS代码:

$(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").click(function() {

        $("ul.tabs li").removeClass("selected"); //Remove any "active" class
        $(this).addClass("selected"); //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;
    });


});

推荐答案

像这样的事情?

var openTab = $(location.hash).filter(".tab_content");

if(openTab.length){
  $("a[href='"+location.hash+"']").click();
}

这篇关于jQuery如何显示带有其他页面链接的特定选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆