// 获取GET请求指定参数 function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var r = decodeURIComponent(window.location.search).substr(1).match(reg); //匹配目标参数 if (r != null) return unescape(r[2]); return null; //返回参数值 } // 获取GET请求所有参数集 function getUrlParams() { var i, param, name, value; var urlParams = {}; var params = location.search.slice( 1 ).split( "&" ); var length = params.length; for ( i = 0; i < length; i++ ) { if ( params[ i ] ) { param = params[ i ].split( "=" ); name = decodeURIComponent( param[ 0 ] ); // Allow just a key to turn on a flag, e.g., test.html?noglobals value = param.length === 1 || decodeURIComponent( param.slice( 1 ).join( "=" ) ) ; if ( urlParams[ name ] ) { urlParams[ name ] = [].concat( urlParams[ name ], value ); } else { urlParams[ name ] = value; } } } return urlParams; }
热门文章