且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用JQuery中的锚点链接到当前页面和其他页面中的特定(隐藏)选项卡?

更新时间:2023-10-28 22:14:40

看到这个:

当你的页面加载时(当dom准备就绪时)这样做

Do this when your page loads (when dom is ready)

var tabId = location.hash; // will look something like "#h-02"

检查哈希值

 if(tabId){
   $(tabId).show(); // this will fired only when url get hash
   $(tabId).siblings().hide(); // this will show only targeted tab 
                               // others get hidden
 }

当你得到这样的网址时会做什么 site.html#tab1

what this will do when you get a url like this site.html#tab1

变量tabId 将具有值#tab1

然后条件为if代码块将显示目标选项卡

then condition in if code block will show the targeted tab