-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
/*
* 获得URL参数值
* @param {String} URL 地址 // url = window.location;
* @param {String} 参数名 可传
* @return {String} 返回结果
*/
getQueryString = function (name){
var pattern = new RegExp("[?&]" + name +"\=([^&]+)","g");
var patternDef = new RegExp("[\?\&][^\?\&]+=[^\?\&]+","g");
var matcher = pattern.exec(window.location.href);
var items = null;
if(name && matcher != null){
try{
items = decodeURIComponent(decodeURIComponent(matcher[1]));
}catch(e){
try{
items = decodeURIComponent(matcher[1]);
}catch(e){
items = matcher[1];
}
}
}else{
patternDef = location.search.match(patternDef);
if(patternDef != null){
var tmpArray;
items = {};
for(var i = 0; i < patternDef.length; i++){
tmpArray = patternDef[i].substring(1).split('=');
items[tmpArray[0]] = tmpArray[1];
}
}
}
return items;
};