1、先截取请求参数字符串;

2、使用decodeURIComponent函数进行解码;

3、正则匹配出参数对象;

function getQueryObject(url) { 
    url = url == null ? window.location.href : url; 
    var search = url.substring(url.lastIndexOf("?") + 1); 
    var obj = {}; 
    var reg = /([^?&=]+)=([^?&=]*)/g; 
    search.replace(reg, function (rs, key, value) { 
        var name = decodeURIComponent(key); 
        var val = decodeURIComponent(value);                
        val = String(val); 
        obj[name] = val; 
        return rs; 
    }); 
    return obj; 
} 

 

posted on 2017-02-22 23:22  百里登风  阅读(646)  评论(0)    收藏  举报