zoukankan      html  css  js  c++  java
  • js 编码、解码与asp.net 编码、解码

    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>
    View Code
  • 相关阅读:
    Cocos2d-x 3.2编译生成Android程序出错Error running command, return code: 2的解决方法
    利用Theme自定义Activity进入退出动画
    Activity的四种launchMode
    android中设置控件获得焦点
    android 反编译 for mac
    android中libs目录下armeabi和armeabi-v7a的区别
    解决Sublime Text 3中文显示乱码(tab中文方块)问题,sublime tab乱码
    mysql教程
    Failed to load c++ bson extension, using pure JS version
    mongodb导出数据
  • 原文地址:https://www.cnblogs.com/linJie1930906722/p/5365282.html
Copyright © 2011-2022 走看看