首先,我们都知道这三个东西都是用来编码的

先来说encodeURI()和encodeURIComponent()

这两个是在转换url时候用来编码解码用的。

有编码就会有解码,

解码就是decodeURI()和decodeURIComponent()

他们的用法很简单,在参数中带入要转码的文字就可实现目的

如:

  encodeURI("我是要编码的文字")

  decodeURI("我是要解码的文字")

  encodeURIComponent("我是要编码的文字")

  decodeURIComponent("我是要解码的文字")


而encodeURI()和encodeURIComponent()的区别其实并不大

主要区别在于:

encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z

encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z

encodeURI主要用于直接赋值给地址栏时候:

1 location.href=encodeURI("http://www.cnblogs.com/Tezml/");

而encodeURIComponent主要用于url的query参数:

1
location.href="http://www.cnblogs.com/Tezml/test.php?a="+encodeURIComponent("我就是我");

而escape,相比于上面那两个,就有所不同了

escape()是编码,unescape()是解码;

escape 方法

对 String 对象编码以便它们能在所有计算机上可读,

escape(charString)
必选项 charstring 参数是要编码的任意 String 对象或文字。

说明
escape 方法返回一个包含了 charstring 内容的字符串值( Unicode 格式)。所有空格、标点、重音符号以及其他非 ASCII 字符都用 %xx 编码代替,

其中 xx 等于表示该字符的十六进制数。例如,空格返回的是 "%20" 。

字符值大于 255 的以 %uxxxx 格式存储。

escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z

注意   escape 方法不能够用来对统一资源标示码 (URI) 进行编码。对其编码应使用 encodeURI 和encodeURIComponent 方法。

最后上一段关于编码解码的demo

<!DOCTYPE html>
<html>
<head>
<title>Tezml_编码解码测试</title>
<meta charset="utf-8">
<meta name="author" content="Tezml" />
<meta name="copyright" content="Tezml" />
<meta name="description" content="Tezml" />
<script type="text/javascript" src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
<div id="wz1"></div>
<div id="wz2"></div>
<div id="wz3"></div>
<div id="wz4"></div>
<div id="wz5"></div>
<div id="wz6"></div>
<div id="wz7"></div>
<div id="wz8"></div>
<div id="wz9"></div>
<div id="wz10"></div>
<div id="wz11"></div>
<div id="wz12"></div>
</body>
<script type="text/javascript">
var chinese="请叫我中文"
var english="place tall me englash"
var Monster=":#&$/@" $("#wz1").html(encodeURI(chinese))//编码 %E8%AF%B7%E5%8F%AB%E6%88%91%E4%B8%AD%E6%96%87 $("#wz2").html(decodeURI(chinese))//解码 请叫我中文 $("#wz3").html(encodeURI(english))//编码 place%20tall%20me%20englash $("#wz4").html(decodeURI(english))//解码 place tall me englash $("#wz5").html(encodeURIComponent(Monster))//编码 %3A%23%26%24%2F%40 $("#wz6").html(encodeURI(Monster))//编码 :#&$/@ $("#wz7").html(escape(chinese))//编码 %u8BF7%u53EB%u6211%u4E2D%u6587 $("#wz8").html(escape(english))//编码 place%20tall%20me%20englash $("#wz9").html(escape(Monster))//编码 %3A%23%26%24/@ $("#wz10").html(unescape(chinese))//编码 请叫我中文 $("#wz11").html(unescape(english))//编码 place tall me englash $("#wz12").html(unescape(Monster))//编码 :#&$/@ </script>
</html>

细讲encodeURI和encodeURIComponent以及escape的区别与应用的更多相关文章

  1. encodeURI()、encodeURIComponent()、escape()

    URI的通用格式如下: /*** 协议://用户名:密码@子域名.域名.顶级域名:端口号/目录/文件名.文件后缀?参数1=值1&参数2=值2+值3#标志 **/ /*** http://use ...

  2. 简单明了区分escape、encodeURI和encodeURIComponent

    一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...

  3. [转]ESCAPE()、ENCODEURI()、ENCODEURICOMPONENT()区别详解

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

  4. Url解码和编码 escape()、encodeURI()、encodeURIComponent()区别详解

    Server.UrlDecode;解码 Server.UrlEncode;编码 url编码是一种浏览器用来打包表单输入的格式.浏览器从表单中获取所有的name和其中的值 ,将它们以name/value ...

  5. escape()、encodeURI()、encodeURIComponent()区别详解 (转)

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

  6. 【转】escape()、encodeURI()、encodeURIComponent()区别详解

    escape().encodeURI().encodeURIComponent()区别详解 原文链接:http://www.cnblogs.com/tylerdonet/p/3483836.html ...

  7. escape()、encodeURI()、encodeURIComponent() 编码解码

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

  8. 简单明了区分escape、encodeURI和encodeURIComponent(转)

    一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...

  9. 【转】简单明了区分escape、encodeURI和encodeURIComponent

    一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...

随机推荐

  1. WebDAV被启用(转)

    WebDAV (Web-based Distributed Authoring and Versioning) 一种基于 HTTP 1.1协议的通信协议.它扩展了HTTP 1.1,在GET.POST. ...

  2. .NET程序猿 - 提升幸福感的组件一览

    1.Newtonsoft.Json.net 操作JSON最简便的方式.  .Net 3.5开始,Framework集成Json序列化器:JavaScriptSerializer,然而Json.net给 ...

  3. Oracle start with connect by prior 用法

    Oracle start with connect by prior 用法    语法: select * from 表名 where 条件1 start with 条件2 connect by pr ...

  4. MySql安装与卸载

    win2003下MySql的配置 准备相关组件 1.MySql安装包 mysql-installer-commercial- 5.6.14.0.msi 2.Microsoft .NETFramewor ...

  5. 简单描述一下XIB与Storyboards,简述它们的优缺点。

    参考答案: 我倾向于纯代码开发,因此所提供的参考答案可能具有一定的个人感情,不过还是给大家说说自己的想法. 优点: XIB:在编译前就提供了可视化界面,可以直接拖控件,也可以直接给控件添加约束,更直观 ...

  6. Web C# 导出Excel 方法总结

    方法1:微软推荐服务器需安装Excel型 依赖: 软件:Office Excel 2007-2013 引用:Microsoft Office 14.0 Object Library 1.1 数据准备 ...

  7. (一)CSS3动画应用 - CSS3 实现 侧边栏展开收起

    @keyframes 规则用于创建动画. @keyframes 中规定某项 CSS 样式,就能创建由当前样式逐渐改为新样式的动画效果 @keyframes 中创建动画时,请把它捆绑到某个选择器,否则不 ...

  8. BZOJ2739 最远点(分治 + 决策单调性)

    2739: 最远点 Time Limit: 20 Sec Memory Limit: 256 MB Description 给你一个N个点的凸多边形,求离每一个点最远的点. Input 本题有多组数据 ...

  9. hdu 2642 Stars

    Problem Description Yifenfei is a romantic guy and he likes to count the stars in the sky. To make t ...

  10. arm汇编(c内嵌汇编及c和汇编互调)

    C语言编译成汇编: arm-linux-gcc -S test.c -o test.S C语言编译成可执行文件: arm-linux-gcc test.c -o test 多个文件编译链接: arm- ...