链接
index.html?id=000000006f0c8ed7016f32291ad0528f&time=2020.01.16&age=18
//获取参数值
function getUrlkey(url) {
var params = {};
var urls = url.split("?");
var arr = urls[1].split("&") || '';
for (var i = 0, l = arr.length; i < l; i++) {
var a = arr[i].split("=");
params[a[0]] = a[1];
}
return params;
}
var urlWWW = window.location.search;
var urlData = getUrlkey(urlWWW);
//设置参数
//转换中文
function getQueryString(name) {
if (name != null) {
return decodeURI(name);
} else {
return null;
}
}
//编码
document.write(encodeURIComponent("http//:www.aa.com.index.html?中文参数"))
document.write("<br/>")
document.write(encodeURIComponent(",/;?;:@&=+$#"))
//encodeURIComponent() 函数将转义用于分隔 URI 各个部分的标点符号
//结果
//http%2F%2F%3Awww.aa.com.index.html%3F%E4%B8%AD%E6%96%87%E5%8F%82%E6%95%B0
//%2C%2F%3B%3F%3B%3A%40%26%3D%2B%24%23
document.write("<br/>")
document.write(encodeURI("http//:www.aa.com.index.html?中文参数"))
document.write("<br/>")
document.write(encodeURI(",/;?;:@&=+$#"))
//结果
// http//:www.aa.com.index.html?%E4%B8%AD%E6%96%87%E5%8F%82%E6%95%B0
// ,/;?;:@&=+$#
//解析
//decodeURIComponent()
//decodeURI()