函数出现时间:
            
        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. HTML5 Canvas ( 图片填充样式 ) fillStyle, createPattern

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. leetcode367

    public class Solution { public bool IsPerfectSquare(int num) { , high = num; while (low <= high) ...

  3. JS获取最终样式

    在使用jqery时,操作什么都很方便,比如获取CSS样式,直接.css加样式名就可以获取你要的,但是JS,就麻烦点,因为有兼容问题,要做兼容,而jqery都是做好了的, 下面就是使用JS获取CSS样式 ...

  4. Simple2D-19(音乐播放器)播放器的源码实现

    使用 BASS 和 ImGui 实现音乐播放器 MusicPlayer. 将播放器和一个文件夹关联起来,程序刚开始运行的时候就从该文件夹加载所有音频文件.而文件夹的路径则保存在配置文件中,所以程序的第 ...

  5. ABAP-SAP的LUW和DB的LUW的区别

    转载:http://www.cnblogs.com/helileng/archive/2010/10/14/1851409.html LUW是Logical Unit of Work,也就是逻辑工作单 ...

  6. WP8.1 在默认浏览器中打开url

    Windows.System.Launcher.LaunchUriAsync(new Uri("http://www.google.com")); PS: This is for ...

  7. LPSN获取菌python脚本

    本文转载于https://mp.weixin.qq.com/s?__biz=MzIxNzEzODA5NQ==&mid=2649373408&idx=1&sn=232c2cb36 ...

  8. hmm 软件的使用

    1)使用HMM模型搜索序列数据库(以青蟹蛋白库为例,简写为qingxie.pep),同源参考序列(query.fas) hmmbuild: 用多重比对序列构建HMM模型:hmmsearch: 使用HM ...

  9. 常用快捷键及eclipise快捷键

    win+R 运行...win+D 桌面win+E 打开我的电脑win+F 搜索 ctrl+D删除光标所在行

  10. alter 和 update的用法和区别

    alter的增加和删除alter table xs_kc add xuefen number;alter table xs_kc drop column xuefen; 删除的时候必须使用column ...