js常用函数.md 462 B

解析URL参数为json


/**
 * 解析URL参数为json对象
 * 
 * @param url
 * @return json
 */
function parseUrlParams(url) {
	url = url || 'http://qq.com/s?a=b#rd';   
	var tmp = url.split('?'),  
		paramStr = (tmp[1] || "").split('#')[0],  
		query = paramStr ? paramStr.split('&') : [],  
		params = {};  
	for (var i=0; i<query.length; i++) {  
		var arg = query[i].split('=');  
		params[arg[0]] = arg[1];  
	}  
	return params;
}