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];
 }
posted @ 2020-10-07 21:25  mingL  阅读(2010)  评论(0编辑  收藏  举报