欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

获取URL的参数值

程序员文章站 2022-07-14 22:31:35
...
//获取地址栏中?后面的
let newUrl= location.search.substr(1)&分割成数组
newUrl.split('&')
会得到下面arr数组中的样子。

造一个假数据:
let arr = ["wd=js%E8%8E%B7%E5%8F%96%E7%BD%91%E5%9D%80%E5%8F%82%E6%95%B0", "rsv_spt=1", "rsv_iqid=0xe40aaddd00040cfd", "issp=1", "f=8", "rsv_bp=1", "rsv_idx=2", "ie=utf-8", "tn=48021271_8_hao_pg", "rsv_enter=1", "rsv_dl=tb", "rsv_sug3=34", "rsv_sug1=25", "rsv_sug7=101", "rsv_t=f903DcwZOnXLbLHK58RRsreGyjmB%2Fpfbnwqo5GDrG8Lgq9dtznpDTeqPz81M53YyNT834SaqcWo", "rsv_sug2=0", "rsv_btype=i", "prefixsug=js%25E8%258E%25B7%25E5%258F%2596%25E7%25…2591%25E5%259D%2580%25E5%258F%2582%25E6%2595%25B0", "rsp=5", "inputT=10395", "rsv_sug4=12035"];
        let n = arr.map((val, index) => {
            console.log(val);
            let ind = val.indexOf("=")
            return val.substr(ind + 1)
        })
        console.log(n);
相关标签: js