js獲取url中的引數值
阿新 • • 發佈:2019-02-09
jsp中頁面的跳轉常常需要帶一些引數,不是前後臺分離,要自己做了。所以找到了如何獲取URL中引數值的方法,這是目前為止小編在本專案中用到最多的方法。
<script type="text/javascript"> function GetQueryString(name) { var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if(r!=null)return unescape(r[2]); return null; } function addGoods(){ alert(GetQueryString("seckillId")); window.location.href = BASE_URL +"/back/busiGoodsParam/add?styleId="+GetQueryString("styleId"); } </script>