js對URL提供:escape,encodeURI,encodeURIComponent 的編碼方法encodeURIComponent:推薦使用,它是將中文、韓文等特殊字符轉換成utf-8格式的url編碼,以是假定給背景轉達參數必要利用encodeURIComponent時必要背景解碼對utf-8撐持(form中的編碼體例和當前頁面編碼體例不異)
1、escape:不編碼字符有69個:*,+,-,.,/,@,_,0-9,a-z,A-Z
2、encodeURI:不編碼字符有82個:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
3、encodeURIComponent:不編碼字符有71個:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
JS編碼:var result=encodeURIComponent(unit);
asp.net解碼:Server.UrlDecode(Request["result"]);
js函數:
encodeURI("url")//編碼
decodeURI("url")//解碼
asp.net的函數:
Server.UrlEncode("url")//編碼
Server.UrlDecode("url")//解碼
JS對URL中的特殊字符的URL編碼,函數是encodeURIComponent,這個函數編碼等於asp.net中的Server.UrlEncode體例。
在asp.net中,利用Request.QueryString[""].ToString()可以直接對編碼后的字符串進行解碼,也可利用Server.UrlDecode體例進行解碼。
在asp.net中,可利用Request.Url.OriginalString來得到URL,利用Request.Url.ToString(),得到到的地點則是解碼過的。
下面是一些使用例子:

1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title></title> 5 <script src="http://localhost:3281/Js/jquery-1.9.1.min.js" type="text/javascript"></script> 6 <script type="text/javascript"> 7 var url = "http://www.cnblogs.com/linJie1930906722?test=測試js對URL的編碼"; 8 var escape_Url = escape(url); //escape_Url=http%3A//www.cnblogs.com/linJie1930906722%3Ftest%3D%u6D4B%u8BD5js%u5BF9URL%u7684%u7F16%u7801 9 var decodeURI_Url = decodeURI(url); // decodeURI_Url=http://www.cnblogs.com/linJie1930906722?test=測試js對URL的編碼 10 var decodeURIComponent_Url = decodeURIComponent(url); //decodeURIComponent_Url=http://www.cnblogs.com/linJie1930906722?test=測試js對URL的編碼 11 var result = "escape_Url=" + escape_Url + " decodeURI_Url=" + decodeURI_Url + " decodeURIComponent_Url=" + decodeURIComponent_Url; 12 console.log(result); 13 alert(result); 14 </script> 15 </head> 16 <body> 17 18 </body> 19 </html>