Javascript获取GET参数

直接上代码

function getQueryVariable() {
    let query = window.location.search.substring(1);
    let key_values = query.split("&");
    let params = {};
    key_values.map(key_val => {
        let key_val_arr = key_val.split("=");
        params[key_val_arr[0]] = key_val_arr[1];
    });
    return params;
}

链接: https://example.com?id=1&type=2

(0)

相关推荐