第一種:參數只能是英文的
function getQuery(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;
}
第二種:參數能夠是中文也能夠是英文
function getQuery(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]); return null;
}
問題:經過js獲取url後面的參數出現中文亂碼?url
解決辦法:採用decodeURI進行解碼spa