JS_0010:获取url中指定的参数

1,获取url中指定的参数

//获取url中指定参数
function getParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var URL = decodeURI(window.location.search);
    var r = URL.substr(1).match(reg);
    if (r != null) {
        //decodeURI() 函数可对 encodeURI() 函数编码过的 URI 进行解码
        return decodeURI(r[2]);
    };
    return null;
}
console.log(getParam('aaa'));

琥珀君的博客
原文地址:https://www.cnblogs.com/eliteboy/p/13230641.html