js获取链接中的参数
获取网页链接中的参数
function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } getUrlParam('id')
方法2
<script> var bb = "https://www.baidu.com/?id=02003390_2_hao_pg&is=123456&si=99999" console.log("结果",cha('si',bb)) function cha(canshu,src) { var arrPara = src.split("&"); var arr = []; for (var i in arrPara) { arr = arrPara[i].split("="); if(arr[0].indexOf(canshu) != -1){ return arr[1] } } } </script>