函数出现时间:
            
        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. Latex Error:‘acmart.cls’ not found 解决方案:

    windows下latex编译ACM论文模板时,出现Latex Error:‘acmart.cls’ not found,解决方案:  首先cd至模板所在目录下,然后运行以下命令:  tex acma ...

  2. MySQL5.7.20 二进制包 在Linux系统中的 安装和配置

    01, 下载安装包 =>  https://dev.mysql.com/downloads/mysql/ 02, 上传到linux系统, 笔者这里安装在 root 目录下, 常见安装在 var/ ...

  3. as3 文档类判断是否被加载

    if (!stage) { trace(("被加载->this.parent:" + this.parent)); }else { trace(("单独打开-> ...

  4. 获取request错误信息

    from: https://stackoverflow.com/questions/19370436/get-errno-from-python-requests-connectionerror 当使 ...

  5. How to Pronounce WH Words — what, why, which

    How to Pronounce WH Words — what, why, which Share Tweet Share Have you noticed that there are two d ...

  6. Python 3 学习笔记(2)

    输入输出 str() 函数人类可读,repr() 解释器可读 rjust() 靠右,ljust() 靠左,center() 居中.zfill() 填0. 名字空间 名字到对象的映射关系被称为名字空间. ...

  7. JavaScipt测试调研

    JavaScript测试调研 前言 与其他语言相似,JavaScript的测试也会包括代码审查.单元测试等内容.本文就JavaScript的测试调研了一些测试工具和测试框架. 相对于其他很多高级语言语 ...

  8. 获得Variant类型

    function GetVariantType(const v: variant): string; begin   case TVarData(v).vType of     varEmpty: r ...

  9. 吴裕雄 python 数据处理(1)

    import time print(time.time())print(time.localtime())print(time.strftime('%Y-%m-%d %X',time.localtim ...

  10. HAproxy-1.6.X 安装部署

    1. 源码包下载及安装 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 root@iZ23tsilmb7Z:/usr/local ...