js在另一个页面获取地址栏参数,可以是中文参数


//获取地址栏参数,可以是中文参数
    function getUrlParam(key) {
        // 获取参数
        let url = window.location.search;
        // 正则筛选地址栏
        let reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
        // 匹配目标参数
        let result = url.substr(1).match(reg);
        //返回参数值
        return result ? decodeURIComponent(result[2]) : null;
    }
发布了52 篇原创文章 · 获赞 11 · 访问量 2460

猜你喜欢

转载自blog.csdn.net/weixin_41705396/article/details/105278441