Hide several divs, show 1 by default, and switch (show/hide) between them based on link click?

前端 未结 3 550
青春惊慌失措
青春惊慌失措 2021-01-19 09:41

I know the show/hide thing has been covered to death on stack, but I just can\'t find a solution that works for me, sorry. I\'ve tried several JS/jQuery solutions that I fou

3条回答
  •  鱼传尺愫
    2021-01-19 10:25

    How about adding some more RESTful behaviour.

    $(function(){
       // get the location hash
       var hash = window.location.hash;
       // hide all
       $('div.content').hide();
       if(hash){
          // show the div if hash exist
          $(hash).show();
       }else{
          // show default 
          $("#ver1").show();
       }
       $("div.containter ul li a").click(function(){
          // hide all
          $('div.content').hide();
          $($(this).attr("href")).show();
       });
    });
    

提交回复
热议问题