简体   繁体   English

如何在第二个html页面加载中基于上一页激活特定选项卡

[英]how to activate particular tab on the basis of previous page in second html page load

I have a pie chart. 我有一个饼图。 Functionality is that when I select a particular section of pie chart, then it redirects to the next page with selected tab. 功能是,当我选择饼图的特定部分时,它会重定向到具有选定选项卡的下一页。 I am able to get value of that pie chart section by using this code: 通过使用以下代码,我能够获得该饼图部分的价值:

 var search = document.URL.split('?')[1]; 

Now my fight is how to enable particular tab on the next page on the basis of value of "search" variable. 现在,我的难题是如何根据“搜索”变量的值启用下一页上的特定选项卡。 Next when user comes direct to this page then 1st tab is enable by default. 接下来,当用户直接进入此页面时,默认情况下启用第一个选项卡。 for this I used the code: 为此,我使用了代码:

<div class="tab-pane in active" id="tab1">

I have tried in many ways(like $("ul.tabs li:first").addClass("active").show() or using eq() ) but have no success. 我已经尝试了多种方式(例如$("ul.tabs li:first").addClass("active").show()using eq() ),但是没有成功。 Please let me know if anyone can help me out. 请让我知道是否有人可以帮助我。

This should do the job: 这应该做的工作:

<script>
    $(function() {
        $("#tabs").tabs();

        var search = document.URL.split('?')[1];
        switch (search) {
            case "error":
                $("#tab1 > a").click();
                break;
            case "suspect":
                $("#tab2 > a").click();
                break;
        }
    });
</script>

<div id="tabs">
    <ul class="nav nav-tabs" id="myTab">
        <li id="tab1" class="active"><a href="#error"data-toggle="tab"> Error</a></li>
        <li id="tab2"><a href="#suspect" data-toggle="tab" >Suspect </a></li>
    </ul>
    <div class="tab-pane in active" id="error">
        Error
    </div>
    <div class="tab-pane" id="suspect">
        Suspect
    </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM