地址:http://localhost:12135/Hotel/HotelMappingView.aspx?city=深圳
获取js
[code=JScript]
function aa(source, name) {
var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
if (reg.test(source)) return RegExp.$2; return "";
};
var city = aa(window.location.href, "city");
得到的参数是
%E6%B7%B1%E5%9C%B3
若何解码或者直接获取中文.?
获取js
[code=JScript]
function aa(source, name) {
var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
if (reg.test(source)) return RegExp.$2; return "";
};
var city = aa(window.location.href, "city");
得到的参数是
%E6%B7%B1%E5%9C%B3
若何解码或者直接获取中文.?
document.write(decodeURI("%E6%B7%B1%E5%9C%B3"));
</script>结果:深圳
是这个方法。
decodeURIComponent() 或者 decodeURI 解码
decodeURI() 函数可对 encodeURI() 函数编码过的URI 进行解码
decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码
encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z