我这里有vbscript写的转换,大家参考下,改成javascript的吧。
--------------譬如,在地址栏输入:http://localhost/中国  
 
在404页面中捕获  Request.ServerVariables("QUERY_STRING")返回的是%E4%B8%AD%E5%9B%BD  
 
到底怎样解码复原成“中国”?  
---------------------------------------------------------------  
 
有点难,帮你Up!  
---------------------------------------------------------------  
 
好像返回的应该是localhost%5C%D6%D0%B9%FA吧,  
它是这样编码的,%5c=/  %d6%d0=中  %b9%fa=国  
 
中=&HD0D6,在VBS中使用Chr(&HD0D6)就可以显示汉字“中”  
国=&HFAB9,Chr(&HFAD9)  
 
所以当第一个字节大于&H7F时,就可能是汉字,小于等&7F就是英文字符,比如上面的%5C=Chr(&H5C)。  
---------------------------------------------------------------  
 
<script  language="vbs">  
var  str="%E4%B8%AD%E5%9B%BD"  
alert  URLDecode(str)  
function  URLDecode(enStr)  
   deStr=""  
   strSpecial  =  "!""#$%&'()*+,/:;<=>?@[\]^`{  |}~%"      
   for  i=1  to  len(enStr)  
       c=Mid(enStr,i,1)  
       if  c="%"  then              
           v=eval("&h"+Mid(enStr,i+1,2))              
           if  inStr(strSpecial,chr(v))>0  then  
                 deStr=deStr&chr(v)                    
                 i=i+2  
           else    
                 v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))  
                 deStr=deStr&chr(v)                    
                 i=i+5  
           end  if  
       else  
           if  c="+"  then  
                 deStr=deStr&"  "    
           else    
                 deStr=deStr&c  
           end  if                              
       end  if  
       URLDecode=deStr  
   next  
end  function  
</script>  
---------------------------------------------------------------  
 
我整理了一下:  
 
<script  language="vbscript">  
dim  str  
str="%5C%D6%D0%B9%FA"  
alert  URLDecode(str)  
function  URLDecode(enStr)  
dim  deStr,strSpecial  
dim  c,i,v  
           deStr=""  
           strSpecial="!""#$%&'()*+,/:;<=>?@[\]^`{  |}~%"  
           for  i=1  to  len(enStr)  
                       c=Mid(enStr,i,1)  
                       if  c="%"  then  
                                   v=eval("&h"+Mid(enStr,i+1,2))  
                                   if  inStr(strSpecial,chr(v))>0  then  
                                               deStr=deStr&chr(v)  
                                               i=i+2  
                                   else  
                                               v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))  
                                               deStr=deStr&chr(v)  
                                               i=i+5  
                                   end  if  
                       else  
                                   if  c="+"  then  
                                               deStr=deStr&"  "  
                                   else  
                                               deStr=deStr&c  
                                   end  if  
                       end  if  
           next  
           URLDecode=deStr  
end  function  
</script>