escape(目前已经被淘汰)是对字符串(string)进行编码(而另外两种是对URL),不会对下列字符编码

ASCII字母  数字  @*/+

最关键的是,当你需要对URL编码时,请忘记这个方法,这个方法是针对字符串使用的,不适用于URL。

encodeURI 方法不会对下列字符编码

ASCII字母 数字 ~!@#>amp;*()=:/,;?+'

encodeURIComponent方法不会对下列字符编码

ASCII字母 数字 ~!*()'

例子,encodeURIComponent会把 http:// 编码成 http%3A%2F%2F 而encodeURI却不会。

场合应该用什么方法

如果你需要编码整个URL,然后需要使用这个URL,那么用encodeURI,如下:
encodeURI("http://www.cnblogs.com/season-huang/some other thing");

编码后会变为
"http://www.cnblogs.com/season-huang/some%20other%20thing";

如果你用了encodeURIComponent,那么结果变为

"http%3A%2F%2Fwww.cnblogs.com%2Fseason-huang%2Fsome%20other%20thing"

3、当你需要编码URL中的参数的时候,那么encodeURIComponent是最好方法。

var param = "http://www.cnblogs.com/season-huang/"; //param为参数
param = encodeURIComponent(param);
var url = "http://www.cnblogs.com?next=" + param;
console.log(url) //"http://www.cnblogs.com?next=http%3A%2F%2Fwww.cnblogs.com%2Fseason-huang%2F"

根据 MDN 的说明,escape 应当换用为 encodeURI 或 encodeURIComponent;unescape 应当换用为 decodeURI 或 decodeURIComponent。

escape,encodeURI,encodeURIComponent 之间的区别和使用的更多相关文章

  1. 转载:escape,encodeURI,encodeURIComponent有什么区别?

    escape unescape encodeURI decodeURI encodeURIComponent decodeURIComponent 这六个方法功能有关联,如果不清楚每一个的作用,很容易 ...

  2. 【转】escape,encodeURI,encodeURIComponent有什么区别?

    在这个页面里面试着搜了一下 「UTF-8」 ,居然没有搜到. escape 和 encodeURI 都属于 Percent-encoding,基本功能都是把 URI 非法字符转化成合法字符,转化后形式 ...

  3. Flex中escape/encodeURI/encodeURIComponent的区别

    Flex中提供了三种转码函数,各有各的区别, escape,encodeURI,encodeURIComponent 这三个函数不仅在flex中有道运用在javascript中同样的含义 ,今天我仔细 ...

  4. escape,encodeURI,encodeURIComponent

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

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

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

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

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

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

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

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

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

  9. escape,encodeURI,encodeURIComponent函数比较

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

随机推荐

  1. AI-Info-Micron-Insight:案例分析:美光使用数据和人工智能来发现、倾听和感觉

    ylbtech-AI-Info-Micron-Insight:案例分析:美光使用数据和人工智能来发现.倾听和感觉 1.返回顶部 1. 案例分析:美光使用数据和人工智能来发现.倾听和感觉 内存芯片制造商 ...

  2. Component概念

    转自:http://www.cnblogs.com/NEOCSL/archive/2012/05/06/2485227.html 1.总结 Component就是组建的意思,可以在DefaultPro ...

  3. shader之texture

    纹理坐标作为属性传递到顶点着色器 texture是OPENGL对象,包含一张或多张相同格式的图片. 它有2中用途: the source of a texture access from a Shad ...

  4. 35.Docker安装Mysql挂载Host Volume

    连个文件系统有块区域Area,我们要做的是把两个Area做文件映射 jesse腾讯云上有个linux的环境,版本比较老了 简书的地址: https://www.jianshu.com/p/b3bf64 ...

  5. HashMap为什么是线程不安全的

    HashMap底层是一个Entry数组,当发生hash冲突的时候,hashmap是采用链表的方式来解决的,在对应的数组位置存放链表的头结点.对链表而言,新加入的节点会从头结点加入. 我们来分析一下多线 ...

  6. iOS三方支付--微信支付/支付宝支付

    一.微信支付 1.注册账号并申请app支付功能 公司需要到微信开放品台进行申请app支付功能 , 获得appid和微信支付商户号(mch_id)和API秘钥(key) . Appsecret(secr ...

  7. c#封装dll

    https://www.cnblogs.com/xingboy/p/10287425.html

  8. Unity3D 自动添加Fbx Animation Event

    http://blog.csdn.net/aa20274270/article/details/52528449 using UnityEngine; using System.Collections ...

  9. vue 开发笔记

    vue 开发记录 marked 插件的使用 import marked from "marked"; import hljs from "highlight.js&quo ...

  10. for循环,递归,函数封装作业

    /******求100以内,所有的奇数和,求100以内,所有的偶数积*******/ // for循环方法   var sum=0; var sum1=1; for(var i=1;i<=100 ...