Js获取当前页面url参数

2022-08-04 10:55:51 浏览数 (1)

代码语言:javascript复制
<script type="text/javascript">
        function getUrlParams(url) {
            const _url = url || window.location.href;
            const _urlParams = _url.match(/([?&])(. ?=[^&] )/igm);
            return _urlParams ? _urlParams.reduce((a, b) => {
                const value = b.slice(1).split('=');
                a[value[0]] = value[1]
                return a;
            }, {}) : {};
        }
        $(function() {
            var code = getUrlParams()
            $(".shareCode").text(code.code)
        });
</script>
url

0 人点赞