浏览器内 JavaScript 可以使用浏览对象模型的window.location.search
属性访问查询字符串。不过,解析该查询字符串的本机支持并不多。(另请参阅如何从 location.search 获取特定参数?)
也许这样的事情会做?
var GET = {}; // I've taken the liberty of re-naming your `QueryString` object
// to just `GET`, kind of in the style of PHP.
// Mostly because I find it confusing to refer to something which
// is not a string (it is an object/map) as a string.
var queryString = window.location.search.replace(/^\?/, ''); // but this: *this* is a string!
queryString.split(/\&/).forEach(function(keyValuePair) {
var paramName = keyValuePair.replace(/=.*$/, ""); // some decoding is probably necessary
var paramValue = keyValuePair.replace(/^[^=]*\=/, ""); // some decoding is probably necessary
GET[paramName] = paramValue;
});
var pageNumber = GET['pageNumber']?Number(GET['pageNumber']):0;
$('#next').click(function() {
GET['pageNumber'] = ++pageNumber;
refresh();
});
function refresh() {
var newQueryString = Object.keys(GET).reduce(function(keyValuePairs, paramName) {
keyValuePairs.push(escape(paramName)+"="+escape(GET[paramName]));
return keyValuePairs;
}, []).join('&');
window.location.search = "?"+newQueryString;
}