jq获取路径参数的方法

路径实例:http://html6.h.m.com/mall_v2/uc/demo/index01.html?act=2&q=10
 
jq获取路径参数的方法
 
$.getUrlParam = function (name) {              //name是路径参数名称
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
 
var xx = $.getUrlParam('q');
console.log(xx)
 
substr() 的参数指定的是子串的开始位置和长度,表示从第几个开始截取
 
unescape() 来解码字符串      
Visit%20W3School%21
Visit W3School!

猜你喜欢

转载自www.cnblogs.com/wszxx/p/9640173.html