How to show or hide tab based on the page url

前端 未结 3 1901
野性不改
野性不改 2021-01-26 11:24

This is my code to flip around the tab and the contents under the tab:

$(function () {
    $(\'#tabs li a\').click(function (e) {
        e.preventDefault();
            


        
3条回答
  •  鱼传尺愫
    2021-01-26 12:05

    It's much easier to use a location hash:

    http://__someurl__#menustate
    

    You can then de-couple the path from the menu state, so you no longer need to keep track of which path translates to which menu state.

    var menustate = document.location.hash;
    $('.' + menustate).addClass('active');
    

    Then you can use whatever url you want:

    www.mysite.com/somepage#recruiting
    

    You can then check the hash value on load and you can also change it, and make it bookmarkable within a single page.

提交回复
热议问题