JS获取url中的参数值

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>queryString方法</title>
</head>
<body>

<script>
    function getQueryString(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = location.search.substr(1).match(reg);
        if(r != null){
            return unescape(decodeURI(r[2]));
        }
        return null;
    }
    //调用
    console.log(getQueryString('nickname'));
</script>

</body>
</html>

 

posted @ 2018-09-19 10:47  SophiaLeeXJ  阅读(191)  评论(0编辑  收藏  举报