//window.search取到的是queryString,如:?a=2&b=3
//将参数存入对象中
function getRequest() {
var url = window.location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]);
//使用decodeURI(),不能用unescape(),会出现乱码
}
}
return theRequest;
}
//获取单个参数
function getQueryString(key){
var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
var result = window.location.search.substr(1).match(reg);
return result?decodeURIComponent(result[2]):null;
}
获取URL地址的中文不乱码
最新推荐文章于 2023-10-19 14:57:47 发布