js.函式parseQuery用於解析url查詢引數

cyccgirl發表於2018-08-21

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"}

相關文章