本篇文章是对JS修改URL参数的实现代码进行了详细的分析介绍
需要的朋友参考下
复制代码 代码如下:
function changeURLPar(url ref value) {
var str = "";
if (urlindexOf(?) != )
str = urlsubstr(urlindexOf(?) + );
else
return url + "?" + ref + "=" + value;
var returnurl = "";
var setparam = "";
var arr;
var modify = "";
if (strindexOf(&) != ) {
arr = strsplit(&);
for (i in arr) {
if (arr[i]split(=)[] == ref) {
setparam = value;
modify = "";
}
else {
setparam = arr[i]split(=)[];
}
returnurl = returnurl + arr[i]split(=)[] + "=" + setparam + "&";
}
returnurl = returnurlsubstr( returnurllength );
if (modify == "")
if (returnurl == str)
returnurl = returnurl + "&" + ref + "=" + value;
}
else {
if (strindexOf(=) != ) {
arr = strsplit(=);
if (arr[] == ref) {
setparam = value;
modify = "";
}
else {
setparam = arr[];
}
returnurl = arr[] + "=" + setparam;
if (modify == "")
if (returnurl == str)
returnurl = returnurl + "&" + ref + "=" + value;
}
else
returnurl = ref + "=" + value;
}
return urlsubstr( urlindexOf(?)) + "?" + returnurl;
}