原文地址:http://www.maoyupeng.com/javascript-get-url-param-value.htmljavascript
本身封裝的一個函數,就是那麼簡單html
getQueryString:function(name) { var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); var r = window.location.search.substr(1).match(reg); if (r != null) { return unescape(r[2]); } return null; }
使用方法:java
var value = this.getQueryString('fightId')
getParam:function(url,name){ var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i"); if (reg.test(url)) return unescape(RegExp.$2.replace(/\+/g, " ")); return ""; },
使用bash
var value = this.getParam("http://www.maoyupeng.com?weibo=hongtu1993@sina.cn","weibo"); // 輸出: hongtu1993@sina.cn