1 function getQueStr(url, ref) //获取参数值 2 { 3 var str = url.substr(url.indexOf('?') + 1); 4 if (str.indexOf('&') != -1) { 5 var arr = str.split('&'); 6 for (i in arr) { 7 if (arr[i].split('=')[0] == ref) 8 return arr[i].split('=')[1]; 9 } 10 } 11 else { 12 return url.substr(url.indexOf('=') + 1) 13 } 14 } 15 16 function setQueStr(url, ref, value) //设置参数值 17 { 18 var str = ""; 19 if (url.indexOf('?') != -1) 20 str = url.substr(url.indexOf('?') + 1); 21 else 22 return url + "?" + ref + "=" + value; 23 var returnurl = ""; 24 var setparam = ""; 25 var arr; 26 var modify = "0"; 27 28 if (str.indexOf('&') != -1) { 29 arr = str.split('&'); 30 31 for (i in arr) { 32 if (arr[i].split('=')[0] == ref) { 33 setparam = value; 34 modify = "1"; 35 } 36 else { 37 setparam = arr[i].split('=')[1]; 38 } 39 returnurl = returnurl + arr[i].split('=')[0] + "=" + setparam + "&"; 40 } 41 42 returnurl = returnurl.substr(0, returnurl.length - 1); 43 44 if (modify == "0") 45 if (returnurl == str) 46 returnurl = returnurl + "&" + ref + "=" + value; 47 } 48 else { 49 if (str.indexOf('=') != -1) { 50 arr = str.split('='); 51 52 if (arr[0] == ref) { 53 setparam = value; 54 modify = "1"; 55 } 56 else { 57 setparam = arr[1]; 58 } 59 returnurl = arr[0] + "=" + setparam; 60 if (modify == "0") 61 if (returnurl == str) 62 returnurl = returnurl + "&" + ref + "=" + value; 63 } 64 else 65 returnurl = ref + "=" + value; 66 } 67 return url.substr(0, url.indexOf('?')) + "?" + returnurl; 68 } 69 70 function delQueStr(url, ref) //删除指定参数值 71 { 72 var str = ""; 73 74 if (url.indexOf('?') != -1) 75 str = url.substr(url.indexOf('?') + 1); 76 else 77 return url; 78 var arr = ""; 79 var returnurl = ""; 80 var setparam = ""; 81 if (str.indexOf('&') != -1) { 82 arr = str.split('&'); 83 for (i in arr) { 84 if (arr[i].split('=')[0] != ref) { 85 returnurl = returnurl + arr[i].split('=')[0] + "=" + arr[i].split('=')[1] + "&"; 86 } 87 } 88 return url.substr(0, url.indexOf('?')) + "?" + returnurl.substr(0, returnurl.length - 1); 89 } 90 else { 91 arr = str.split('='); 92 if (arr[0] == ref) 93 return url.substr(0, url.indexOf('?')); 94 else 95 return url; 96 } 97 } 98 var str = window.location.href.replace(/(?|#)[^"]*/g, '');//删除所有参数值