url传参过程中文字需编码、解码使用

1.链接进行编码跳转:window.location.href = encodeURI(url)

2.获取当前链接进行解码decodeURI(window.location);

3.获取url中参数值:

获取参数代码:

 

 1 function GetQueryString(name,isDecode)
 2 {
 3     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
 4     if(isDecode){
 5         var r = decodeURI(window.location.search).substr(1).match(reg);
 6     }else{
 7         var r = window.location.search.substr(1).match(reg);
 8     }
 9     if(r!=null)return  unescape(r[2]); return null;
10 }
 
原文地址:https://www.cnblogs.com/juicy-initial/p/9254356.html