获取浏览器地址栏URL的参数

213 阅读1分钟
function getRequest() {   
    var url = decodeURI(decodeURI(location.search));   
    //console.log( decodeURI(decodeURI(location.search)))   
    var theRequest = new Object();   
    if(url.indexOf("?") != -1) {       
        var str = url.substr(1);       
        strs = str.split("&");       
        for(var i = 0; i < strs.length; i++) {           
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);       
        }   
    }  
 return theRequest; 
}