Js 之获取当前链接地址并修改QueryString
作者:互联网
一、代码
function setQueryString(key, val) { var url = window.location.href.split('?'), search=url[1]; //获取地址栏 "?"后的内容 var query = {}; if (search) { search.split('&').forEach((item) => { var arr = item.split('='); query[arr[0]] = arr[1]; }); } query[key] = val; var queryArr = []; for (var p in query) { queryArr.push(p + '=' + query[p]); } return url[0]+'?'+queryArr.join('&'); };
标签:arr,QueryString,search,Js,queryArr,split,var,query,链接 来源: https://www.cnblogs.com/yang-2018/p/15730838.html