History.JS - replaceState追加

时间:2014-03-01 15:27:22

标签: javascript jquery html history.js

我使用的是History.js框架,我只使用 replaceState 方法。

我的问题是关于replaceState行为,因为它取代了所有的查询字符串。

History.replaceState(null, null, "?tab=2");

因此,当我运行上述代码时,所有参数都会被删除,并添加?tab = 2

www.yoursite.com/accounts?tab=2

标签= 2

外,是否可以保持其他参数不变

www.yoursite.com/accounts?country=1&city=2&tab=2

1 个答案:

答案 0 :(得分:1)

不,你必须自己构建新的查询字符串。

function append(p) {
    return (location.search ? location.search+"&" : "?") + p; // + location.hash
}
history.replaceState(null, null, append("tab=2"));