Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /www/wwwroot/fawdlstty.com/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /www/wwwroot/fawdlstty.com/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
对于网页前台,有时候是需要获取网页参数的,比如https://www.fawdlstty.com/?p=57,js如何获取参数呢?这一个参数还好,如果参数多了那么解析就费事了。下面提供一种方法实现最便捷的方式获取网页参数。实现代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 | function getRequest() { var url = location.search; var obj = {}; if (url.indexOf('?') != -1) { url = url.substring(url.indexOf('?') + 1).split('&'); for (var i = 0; i < url.length; i++) { var strs = url[i].split('='); obj[strs[0]] = unescape(strs[1]); } } return obj; } |
代码量很小,使用方式如下,比如,获取参数名为p的值:
1 2 | var param = getRequest(); alert(param['p']); |
调用也是相当方便呢