函数出现时间:
            
        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. 0_Simple__template

    简单的 CUDA 应用模板,白送的 Sample. ▶ 源代码 //template_cpu.cpp extern "C" void computeGold(float *, co ...

  2. leetcode405

    public class Solution { string ConverToHex(string bit) { var s = ""; switch (bit) { " ...

  3. Git revert merge

    从history1分出来的A, B两个branch A上有一些更改,例如 changeA2 changeA1 history1 B上有一些更改,例如 changeB2 changeB1 history ...

  4. $.ajax的重写

    //2018-07-05 项目使用 var _ajax=$.ajax; //重写jquery的ajax方法 $.ajax=function(opt){ //备份opt中error和success方法 ...

  5. FreeMarkerUtl

    /** * @title FreeMarkerUtl * @description 模板文件工具类 * @author maohuidong * @date 2017-07-05 */public c ...

  6. 磁盘IO过高时的处理办法

    针对系统中磁盘IO负载过高的指导性操作 主要命令:echo deadline > /sys/block/sda/queue/scheduler 注:以下的内容仅是提供参考,如果磁盘IO确实比较大 ...

  7. python 学习备忘

    list列表排序 def listdir(path): #返回一个排序后的目录list files=os.listdir(path) files.sort(key=lambda x:str(x[:-4 ...

  8. freemaker基础语法

      1.freemarker中Request,Session的用法:java块:request.getSession().setAttribute("qq","http: ...

  9. 如何打开Windows Server 2008 R2的域安全策略

    今天安装了Windows Server 2008 R2系统,并且建了域环境,在添加新用户的时候,发现用简单的密码时域安全策略提示密码复杂度不够,于是我就想在域安全策略里面把密码复杂度降低一点,但是很快 ...

  10. SpringDataRedis事务 专题

    5.10.1. @Transactional SupportTransaction Support is disabled by default and has to be explicitly en ...