1. 跳转前页面代码处理,仅罗列href跳转方法,其他如jQuery跳转等原理一直不再赘述:
<a href="newUrl.html?para=1&id=2&page=3">点击文字跳转</a>
2. 跳转后页面代码处理:
<script> function getUrl(url) { var arr = url.split('?'); var params = arr[1].split('&'); //得到[a=1,b=2,c=3] var obj = {}; for (var i = 0; i < params.length; i++) { var param = params[i].split('='); //得到{[a,1],[b,2],[c,3]} obj[param[0]] = param[1]; } return obj; } //将url参数传入函数,注意如果是jQuery的方法传入,请替换括号内变量 var urlParams = getUrl(window.location.href) console.log(urlParams) </script>
标签:url,param,参数,split,跳转,var,页面 From: https://www.cnblogs.com/irjeff/p/16704582.html