JS 获取URL中指定的参数的值

通过location.search可以获取到url拼接的参数(前面带有?号)

function getUrlParams(name) {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    let param = window.location.search.substr(1).match(reg);
    return param && param[2];
 }
原文地址:https://www.cnblogs.com/xingguozhiming/p/13779383.html