A-A+
javascript 获取Url指定参数的值
【注意:此文章为博主原创文章!转载需注意,请带原文链接,至少也要是txt格式!】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <!DOCTYPE HTML> <!--STATUS OK--> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> </head> <body> <script type="text/javascript"> getQueryValue = function(b, c) { var d = new RegExp("(^|&|\\?|#)" + stringescapeReg(c) + "=([^&#]*)(&|\x24|#)",""); var a = b.match(d); if (a) { return a[2] } return null }; stringescapeReg = function(a) { return String(a).replace(new RegExp("([.*+?^=!:\x24{}()|[\\]/\\\\])","g"), "\\\x241") } //示例URL地址: http://woj.app/xxx.html?step=123123&url=https%3A%2F%2Fwoj.app%2Fxxx.html var step = getQueryValue(location.href,'step'); //第一个参数为需要获取的当前的URL地址:location.href 第二个参数为要获取的URL地址的参数 var url = decodeURIComponent(getQueryValue(location.href,'url')); alert(step); alert(url); </script> </body> </html> |
代码中已经说的很明白了,自己看吧。
布施恩德可便相知重
微信扫一扫打赏
支付宝扫一扫打赏