// 取得查询字符串
function getQueryString(name, url) {
var sReg = "[\\?\\&](" + name + ")=([^\\&#]*)";
var reg = new RegExp(sReg, "i");
if (url == null || url == "") {
url = location.search;
}
var match = url.match(reg);
if (match != null) {
var result = match[2];
result = decodeURIComponent(result);
return result;
}
return null;
}
// 设置URL查询字符串
function setQueryString(key, value, url) {
if (url == null || url == "") {
url = location.href;
}
var s = key + "=" + encodeURIComponent(value);
reg = new RegExp("([\\?\\&])(" + key + "=[^\\&]*)");
url = url.replace(reg, "$1" + s);
if (reg.test(url) == false) {
if (url.indexOf("?") > -1) {
url = url + "&" + s;
} else {
url = url + "?" + s;
}
}
return url;
}