js获得url内的参数

 

 

        /**
         * js获得url内的参数
         * 返回值: string or undefined
         * 使用方法:$_GET['from']
         */
        var $_GET = (function() {
        var search = location.search;
        if (search == '')
        {
            return {};
        }

        search = search.split('?')[1];
        search = search.split('&');
        var get = {};
        for (var i in search)
        {
            var j = search[i].split('=');
            get[j[0]] = j[1];
        }
        return get;

        })();

 

posted @ 2014-09-19 18:28  耐得住寂寞  阅读(216)  评论(0编辑  收藏  举报