首页 > 代码库 > URL获取并修改参数【转】
URL获取并修改参数【转】
1 function changeURLPar(url, ref, value) { 2 var str = ""; 3 if (url.indexOf(‘?‘) != -1) 4 str = url.substr(url.indexOf(‘?‘) + 1); 5 else 6 return url + "?" + ref + "=" + value; 7 var returnurl = ""; 8 var setparam = ""; 9 var arr;10 var modify = "0";11 if (str.indexOf(‘&‘) != -1) {12 arr = str.split(‘&‘);13 for (i in arr) {14 if (arr[i].split(‘=‘)[0] == ref) {15 setparam = value;16 modify = "1";17 }18 else {19 setparam = arr[i].split(‘=‘)[1];20 }21 returnurl = returnurl + arr[i].split(‘=‘)[0] + "=" + setparam + "&";22 }23 returnurl = returnurl.substr(0, returnurl.length - 1);24 if (modify == "0")25 if (returnurl == str)26 returnurl = returnurl + "&" + ref + "=" + value;27 }28 else {29 if (str.indexOf(‘=‘) != -1) {30 arr = str.split(‘=‘);31 if (arr[0] == ref) {32 setparam = value;33 modify = "1";34 }35 else {36 setparam = arr[1];37 }38 returnurl = arr[0] + "=" + setparam;39 if (modify == "0")40 if (returnurl == str)41 returnurl = returnurl + "&" + ref + "=" + value;42 }43 else44 returnurl = ref + "=" + value;45 }46 return url.substr(0, url.indexOf(‘?‘)) + "?" + returnurl;47 }
URL获取并修改参数【转】
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。