我写了一个函数来完成这个,它重新加载当前页面,并且完全支持更改现有的 url 变量(以及添加新变量)。您所要做的就是将对象文字传递给函数。见这里:https ://stackoverflow.com/a/10235376/733347
在你的情况下,你需要做的就是调用函数
reloadWithQueryStringVars({"type": "all"});
或者
reloadWithQueryStringVars({"type": "confirmed"});
或者
reloadWithQueryStringVars({"type": "unconfirmed"});
关于按钮的点击事件
这是整个函数供参考:
function reloadWithQueryStringVars (queryStringVars) {
var existingQueryVars = location.search ? location.search.substring(1).split("&") : [],
currentUrl = location.search ? location.href.replace(location.search,"") : location.href,
newQueryVars = {},
newUrl = currentUrl + "?";
if(existingQueryVars.length > 0) {
for (var i = 0; i < existingQueryVars.length; i++) {
var pair = existingQueryVars[i].split("=");
newQueryVars[pair[0]] = pair[1];
}
}
if(queryStringVars) {
for (var queryStringVar in queryStringVars) {
newQueryVars[queryStringVar] = queryStringVars[queryStringVar];
}
}
if(newQueryVars) {
for (var newQueryVar in newQueryVars) {
newUrl += newQueryVar + "=" + newQueryVars[newQueryVar] + "&";
}
newUrl = newUrl.substring(0, newUrl.length-1);
window.location.href = newUrl;
} else {
window.location.href = location.href;
}
}