1. 程式人生 > >二、實現從一頁面跳轉到指定模組的位置,並將該模組在主區域中顯示出來

二、實現從一頁面跳轉到指定模組的位置,並將該模組在主區域中顯示出來


1、跳轉指定頁面一般使用如下程式碼<a href="weixin.html#person" class="back" id="back-person"></a>但跳轉時顯示“微信”模組且導航中“微信”按鈕點亮。2、為了在主區域顯示出要跳轉到的指定person模組,可以先獲取當前的url中的hash,然後再隱藏其他模組

function jumpToCurPage() {
if (!document.getElementById) return false;
if (!document.getElementsByTagName) return false;
if (!document.getElementsByClassName) return false;
var locationHash = window.location.hash.split("#")[1];

selectNav(locationHash);
showSection(locationHash);
return false;
}

其中selectNav()和showSection()兩個函式和上一篇文章裡面的程式碼一樣