我正在面對拆分和解析window.location.hash問題。拆分和解析window.location.hash
首先,我們得到的哈希幾個參數,例如:
#loc=austria&mr=1&min=10&max=89
正如你肯定會看到它被搜索創建。當用戶點擊分頁鏈接頁面正在重新加載散列。到現在爲止還挺好。
我創建功能INITIALISE()正在調用每當有在URL中的hash:
if (window.location.hash) {
var params = (window.location.hash.substr(1)).split("&");
for (i = 0; i < params.length; i++)
{
var a = params[i].split("=");
// Now every parameter from the hash is beind handled this way
if (a[0] == "loc")
{
locationList(a[1]);
}
}
}
Everythig幾乎工作......當我選擇所有搜索PARAMS哈希正在...切。對於我來說不明原因。我試圖用if(params.indexOf('loc'))
而不是a[0] == "loc"
沒有任何運氣。
你能幫我一把嗎?
編輯
當然,我是用VAR一個= ...在循環,那也只是複製粘貼錯誤。
*當我選擇所有搜索PARAMS哈希正在...切*。我不明白這句話...... – 2011-04-13 09:12:48
當我重新加載頁面後,我有這樣的'#loc = austria&mr = 1&min = 10&max = 89'這樣的散列,它就是'#loc = austria&mr = 1'。 – user948438237 2011-04-13 09:17:02
你有沒有試過'if(params [i] .indexOf('loc'))'? – 2011-04-13 09:32:45