JS 获取url问号后面的所有参数

var params = (function oneValues() {
    var query = location.search.substr(1)
    query = query.split('&')
    var params = {}
    for (let i = 0; i < query.length; i++) {
        let q = query[i].split('=')
        if (q.length === 2) {
            params[q[0]] = q[1]
        }
    }
    return params  //返回?号后面的参数名与参数值的数组
}());

 

posted @ 2018-12-06 14:04  格鲁特baby  阅读(3564)  评论(0编辑  收藏  举报