日期:2014-05-16  浏览次数:20453 次

javascript实现把URL参数解析为一个对象
var GET = {};
var loc = String(document.location);
var pieces = loc.substr(loc.indexOf('?') + 1).split('&');
for (var i = 0; i < pieces.length; i++){
    var keyVal = pieces[i].split('=');
    GET[keyVal[0]] = decodeURIComponent(keyVal[1]);
}

?用法:http://blackbaby.iteye.com/admin/blogs/new?a=1&b=2,?? alert(GET["a"]);