url中请求参数转js对象
function searchObj(search) { var obj = null; search = search || window.location.search; if(search){ search = decodeURIComponent(search); if(search.indexOf('?') !== -1) search = search.substring(1); if(search){ obj = {}; $.each(search.split('&'),function (i,v) { if(v){ var arr = v.split('='); if(arr[0] && arr[1]!==undefined) obj[arr[0]] = arr[1]; } }); } } return obj; }
以上参数可以是表单序列化字符串,并且参数去重。