函数出现时间:
            
        escape()                                javascript 1.0
            
        encodeURI()                         javascript 1.5
 
        encodeURIComponent()     javascript 1.5
 
    函数功能介绍:
        
        escape()   :     采用ISO Latin字符集对指定的字符串进行编码。所有的空格符、标点符号、特殊字符以及其他非ASCII字符都会转化成%xx格式的字符编码(xx代表此字符在字符集表里编码的16进制数字)。比如,空格符的对应编码是%20。不会对ASCII字符和数字进行编码。不会被此方法编码的字符:@ * / +,反向编码函数:unescape()
 
        encodeURI():    把URI字符串采用UTF-8编码格式转化成escape格式的字符串。不会被此方法编码的字符:! @ # $ & ( ) = : / ; ? + ',反向编码函数:decodeURI()
        
        encodeURIComponent():把URI字符串采用URF-8编码格式转化成escape格式的字符串。与encodeURI相比,这个函数会将更多的字符进行编码,比如"/"等字符。所以如果字符串里面包含了URI的几个部分的话,不能用这个来进行编码。否则“/”字符被编码后将URL显示错误。不会被此方法编码的字符:! * ( ),反向编码函数:decodeURIComponent()
 
    测试demo:
 
        var url = "http://localhost:8080/pro?a=1&b=张三&c=aaa";
        var url1 = escape(url);                                           http%3A//localhost%3A8080/pro%3Fa%3D1%26b%3D%u5F20%u4E09%26c%3Daaa         
        var url2 = encodeURI(url);                                     http://localhost:8080/pro?a=1&b=%E5%BC%A0%E4%B8%89&c=aaa   
        var url3 = encodeURIComponent(url);                 http%3A%2F%2Flocalhost%3A8080%2Fpro%3Fa%3D1%26b%3D%E5%BC%A0%E4%B8%89%26c%3Daaa   
 
      
var vurl2 = unescape(url2);                                    http://localhost:8080/pro?a=1&b=张三&c=aaa
var vurl3 = decodeURI(url3);                                  http://localhost:8080/pro?a=1&b=张三&c=aaa
        var vurl1 = decodeURIComponent(url1);              http://localhost:8080/pro?a=1&b=张三&c=aaa     
         
    具体用法:
 
        escape()函数用于js对字符串进行编码。不常用
 
        encodeURI()用于整个url跳转,比如:
               转化前: location.href = "http://localhost:8080/pro?a=1&b=张三&c=aaa";
               转化后: location.href = "http://localhost:8080/pro?a=1&b=%E5%BC%A0%E4%B8%89&c=aaa"
               本例中只是将中文转成%...,传过去再解码就可以拿到中文
 
        encodeURIComponent()用于参数的传递,参数包含特殊字符可能会造成间断。比如:
               var paramUrl = "http://localhost:8080/aa?a=1&b=2&c=3";
               var url = "http://localhost:8080/pp?a=1&b="+ paramUrl ;
                应该使用encodeURIComponent()进行转码,
                结果:http://localhost:8080/pp?a=1&b=http%3A%2F%2Flocalhost%3A8080%2Faa%3Fa%3D1%26b%3D2%23%26c%3D3
 
 
 

URL编码转换函数:escape()、encodeURI()、encodeURIComponent()的更多相关文章

  1. url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介

    url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介 2014年10月12日 16806次浏览 引子 浏览器URl地址,上网一定会用到,但是浏 ...

  2. url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介【转】

    引子 浏览器URl地址,上网一定会用到,但是浏览器地址有中文或者浏览器url参数操作的时候,经常会用到encodeURIComponent()和decodeURIComponent()以及encode ...

  3. URL编码转换函数:escape()、encodeURI()、encodeURIComponent()讲解

    转自:https://www.cnblogs.com/douJiangYouTiao888/p/6473874.html 函数出现时间:         escape()                ...

  4. JavaScript URL编码转换函数 encodeURIComponent()

    encodeURIComponent()定义和用法 encodeURIComponent() 函数可把字符串作为 URI 组件进行编码. 语法:encodeURIComponent(URIstring ...

  5. JavaScript中编码函数escape,encodeURI,encodeURIComponent

    第一:escape():对字符串进行编码,escape()不编码的字符:@*/+ 第二:encodeURI() 函数可把字符串作为 URI 进行编码.不会进行转义的:;/?:@&=+$,# 第 ...

  6. JavaScript中有三个可以对字符串编码的函数,分别是: escape(),encodeURI(),encodeURIComponent()

    JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...

  7. JavaScript中有对字符串编码的三个函数:escape,encodeURI,encodeURIComponent

    JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...

  8. 浏览器编码的函数简介escape(),encodeURI(),encodeURIComponent()

    1.escape() escape()是js编码函数中最古老的一个.虽然这个函数现在已经不提倡使用了,但是由于历史原因,很多地方还在使用它,所以有必要先从它讲起. 实际上,escape()不能直接用于 ...

  9. escape,encodeURI,encodeURIComponent函数比较

    escape,encodeURI,encodeURIComponent函数比较 js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数 ...

随机推荐

  1. Windows系统日常运维

    WINDOWS系统日常运维 http://www.docin.com/p-677263438.html

  2. controller检查header

    以前都只能拿到request再检查,其实有相应的注解. public Result updateRecentScore(@RequestBody Map map, @RequestHeader(&qu ...

  3. java 调用短信 api 接口发送短信

    参考:   https://blog.csdn.net/u014793522/article/details/59062014 参考 :https://blog.csdn.net/Lu_shilusi ...

  4. JAVA时间进行比较和转换,时间加减得到天数

    转自:https://blog.csdn.net/iteye_8535/article/details/82246006 JAVA时间进行比较和转换,时间加减得到天数 1. 把时间类型的字符串转为DA ...

  5. VBA 浏览文件夹

    Private Function SelectFolder() As String        With Application.FileDialog(msoFileDialogFolderPick ...

  6. as2 无法加载类或接口

    1.最大问题就是可能新建文件的时候选择as3的as或者直接复制了as3的as文件过来修改.as文件必须是2的 2.类名是否一致 3.包引用是否正确

  7. 17 网络编程 C/S架构介绍

    1.什么是C/S架构 C指的是client(客户端软件),S指的是Server(服务器软件),本章的重点是教大家写一个C/S架构的软件,实现服务端软件与客户端软件基于网络通信. 2.计算机基础的知识- ...

  8. ABAP-年月期间搜索帮助

    selection-screen begin of block block1 with frame title text-. parameters:p_mon1 like s031-spmon, p_ ...

  9. scala spark 调用hivecontext

    import org.apache.spark.rdd.RDD def save(data: RDD[ModelReplay], modelKey: String, dt: String): Unit ...

  10. fm 讲解加代码

    转自: 博客 http://blog.csdn.net/google19890102/article/details/45532745/ github https://github.com/zhaoz ...