js获取地址栏参数

var getUrlParam = function(name){
        var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)"),
            r = window.location.search.substr(1).match(reg);
        console.log(window.location.search)
        if (r!=null){
            return unescape(r[2]);
        }else {
            return null;
        }
    }
    //   http://localhost:8000?param=1
    console.log(getUrlParam("param")) //  输出1  字符串型
posted @ 2017-08-21 19:57  Stone&IT  阅读(112)  评论(0编辑  收藏  举报