我正在面对拆分和解析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