parseQuery 函式實現 var parseQuery = function(query){ var reg = /([^=&\s]+)[=\s]([^=&\s])/g; var obj = {}; while(reg.exec(query)){ obj[RegExp.$1] = RegExp.$2; } return obj; }
例子: var jerry = parseQuery("name=jerry&age=1"); jerry; 返回值:{name: " jerry ", age: "1"}