分為兩種url,一種是帶#‘錨點’的url,一種是平常的url
現(xiàn)在web開發(fā)多了一種hository模式,因此需要重新封裝一個截取url參數(shù)值的方法。
有錨點的url參數(shù)值獲取 :
```
function getQueryString(key){
?var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
var result = window.location.hash.split('?')[1].match(reg);
? ? ? ? return result?decodeURIComponent(result[2]):null;
? ? }
getQueryString('key')
```
普通的url參數(shù)獲取
```
getQueryString(key)?{
??????var?reg?=?new?RegExp("(^|&)"?+?key?+?"=([^&]*)(&|$)");
??????var?result?=?window.location.search.substr(1).match(reg);
??????return?result???decodeURIComponent(result[2])?:?null;
????},
```