常用common方法

1.根据url中携带的参数名获取参数值

/**
 * 获取url中的参数
 */
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}

用法:url :http://localhost:8003/htmls/xxxxxxxx.html?guid=b3905077-ac9a-b9ba-5ba0-8ad411fa7d69&iType=2

var iType = getUrlParam("iType");

console.log(iType )

猜你喜欢

转载自www.cnblogs.com/liangpi/p/10981125.html