匹配所有:html
var query = location.href.substr(location.href.indexOf('?') + 1); // console.log(query); var patt = new RegExp('([^=]*)=([^&#]*)', 'g'); var result; while((result = patt.exec(query)) != null) { if(result[1].substr(0, 1) == '&') { params[result[1].substr(1)] = result[2]; } else { params[result[1]] = result[2]; } }
其餘參考:https://www.cnblogs.com/myzhibie/p/4365142.htmlcode