每日一学

作者: Amber貝貝 | 来源:发表于2019-07-16 11:11 被阅读0次

    1.获取地址栏参数

    方法一:

    const url = 'https://sls.console.aliyun.com/next/project/test-hz-hbb/logsearch/amber-hsinga?spm=5176.2020520112.108.d7.794b34c0Ocwl5o&hiddenBack=true';
    
    function getUrlParams(url, hiddenBack) {
        let oUrl = new URL(url);
        return oUrl.searchParams.get(hiddenBack);
    }
    getUrlParams(url,'hiddenBack');    // "true"
    

    方法二:

    const url = 'https://sls.console.aliyun.com/next/project/test-hz-hbb/logsearch/amber-hsinga?spm=5176.2020520112.108.d7.794b34c0Ocwl5o&hiddenBack=true';
    
    function getURLParams(url){ 
        let q={} 
        url.replace(/([^?&=]+)=([^&]+)/g,(_,k,v)=>q[k]=v) 
        return q 
    }
    getURLParams(url)
     //{spm: "5176.2020520112.108.d7.794b34c0Ocwl5o", hiddenBack: "true"}
    

    相关文章

      网友评论

        本文标题:每日一学

        本文链接:https://www.haomeiwen.com/subject/dmwzcctx.html