function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);//search,查询?后面的参数,并匹配正则
if(r!=null)return decodeURI(r[2]); return null;
}
本来使用的解码是unescape() 所以出错,改为decodeURI解码就OK了
Js中escape,unescape,encodeURI,encodeURIComponent区别:
1.传递参数时候使用,encodeURIComponent否则url中很容易被”#”,”?”,”&”等敏感符号隔断。
2.url跳转时候使用,编码用encodeURI,解码用decodeURI。
3.escape() 只是为0-255以外 ASCII字符 做转换工作,转换成的 %u**** 这样的码,如果要用更多的字符如 UTF-8字符库 就一定要用 encodeURIComponent() 或 encodeURI() 转换才可以成 %nn%nn 这的码才可以,其它情况下escape,encodeURI,encodeURIComponent编码结果相同,所以为了全球的统一化进程,在用 encodeURIComponent() 或 encodeURI() 代替 escape() 使用吧!