在WEB(我是在Asp.net环境,相信其它也一样.)开发当中,当你传有中文值的URL(如http://localhost/Test/test.aspx?name=张三),你会发现你通过Request.Questring["Name"]服务器处理时获取的并不是你要的"张三",而是一些奇怪的字符,问题就来了。这时候你可用通过Javascript的window.encodeURIComponent方法转换你的URL,将中文部分转换成encode。贴入javascript实现的方法.

 function qs(url)
 { 
   
if (window.RegExp && window.encodeURIComponent)
    {
      
return encodeURIComponent(url); 
    } 
 } 
 
你可以参照GOOGLE的方法:
function qs(el) 
{
  
if (window.RegExp && window.encodeURIComponent)
  {
     
var ue=el.href;var qe=encodeURIComponent(document.gs.q.value);
     
if(ue.indexOf("q=")!=-1)
    {
      el.href
=ue.replace(new RegExp("q=[^&$]*"),"q="+qe);
     }
     
else
    {
      el.href
=ue+"&q="+qe;
    }
  }
  
return 1;
}

相关文章:

  • 2021-09-17
  • 2021-07-29
  • 2022-12-23
  • 2023-03-30
  • 2021-05-29
  • 2022-12-23
  • 2021-10-22
  • 2021-06-06
猜你喜欢
  • 2021-07-22
  • 2021-07-30
  • 2021-10-03
  • 2021-05-21
  • 2021-09-15
  • 2021-09-24
相关资源
相似解决方案