原文地点:http://www.maoyupeng.com/javascript-get-url-param-value.html
从地点栏上猎取地点,且依据参数名猎取值
本身封装的一个函数,就是那末简朴
getQueryString:function(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
运用方法:
var value = this.getQueryString('fightId')
依据称号猎取地点字符串中的参数值
getParam:function(url,name){
var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
if (reg.test(url)) return unescape(RegExp.$2.replace(/\+/g, " "));
return "";
},
运用
var value = this.getParam("http://www.maoyupeng.com?weibo=hongtu1993@sina.cn","weibo");
// 输出: hongtu1993@sina.cn