一、代码
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('&'); };