在js中获取地址栏参数

在js中获取地址栏参数


//根据传递过来的参数name获取对应的值
function getParameter(name) {
var reg = new RegExp("(^|&)" + name + “=([^&]*)(&|$)”,“i”);
var r = location.search.substr(1).match(reg);
if (r!=null) return (r[2]); return “”;
}
把此段代码封装成一个getParameter.js文件
然后再js代码中直接调用方法即可
var name = getParameter(name) ;
对于有中文的参数 还要进行解码
name = decodeURI(name);

猜你喜欢

转载自blog.csdn.net/weixin_42957419/article/details/83056821