獲取所有query string
function queryStringAll() { var reg = /(?:^|&)([^&]+)=([^&]+)(?=&|$)/g, args = {}, qs = location.search || location.hash; qs = qs.slice(qs.indexOf('?') + 1); while (result = reg.exec(qs)) { args[result[1]] = result[2]; } return args; }
獲取指定name的query string
function queryString(key) { var reg = new RegExp('(?:^|&)' + key + '=([^&]+)(?=&|$)'), qs = location.search || location.hash; qs = qs.slice(qs.indexOf('?') + 1); return (result = qs.match(reg)) == null ? null : result[1]; }
參考:http://www.cnblogs.com/jiekk/archive/2011/06/28/2092444.html
http://www.cnblogs.com/sohighthesky/archive/2010/01/21/1653126.html