encodeURI、encodeURIComponent的区别
一.区别.
- 这两个函数功能上面比较接近,但是有一些区别。
- encodeURI:不会进行编码的字符有82个 :!,#,$,&,’,(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
- encodeURIComponent:不会进行编码的字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
二.总结.
encodeURI() 用于编码整个URI,因为URI中的合法字符都不会被编码转换。encodeURIComponent方法在编码单个URIComponent(指请求参数)应当是最常用的,它可以讲参数中的中文、特殊字符进行转义,而不会影响整个URL。
三.示例.
1、 encodeURI()
<script type="text/javascript">document.write(encodeURI("http://www.w3school.com.cn/")+ "<br />")document.write(encodeURI("http://www.w3school.com.cn/My first/"))document.write(encodeURI(",/?:@&=+$#"))</script>输出:http://www.w3school.com.cn/http://www.w3school.com.cn/My%20first/,/?:@&=+$#
对整个URL进行编码,而URL的特定标识符不会被转码。
2、 encodeURIComponent()
例1:<script type="text/javascript">document.write(encodeURIComponent("http://www.w3school.com.cn/"))document.write("<br />")document.write(encodeURIComponent("http://www.w3school.com.cn/p 1/"))document.write("<br />")document.write(encodeURIComponent(",/?:@&=+$#"))</script输出:http%3A%2F%2Fwww.w3school.com.cn
http%3A%2F%2Fwww.w3school.com.cn%2Fp%201%2F
%2C%2F%3F%3A%40%26%3D%2B%24%23
例2:<script language="javascript">document.write('<a href="http://passport.baidu.com/?logout&aid=7&u='+encodeURIComponent("http://cang.baidu.com/bruce42")+'">退出</a>');</script>
对URL中的参数进行编码,因为参数也是一个URL,如果不编码会影响整个URL的跳转。
四.
关于escape说两点:
ECMAScript 3中已经不提倡使用这个函数了,所以我们还是少用吧。
escape不会编码的字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z
encodeURI、encodeURIComponent的区别相关推荐
- encodeURI encodeURIComponent 的区别,和使用场景
encodeURI encodeURIComponent 的区别,和使用场景 一. ncodeURI 和 encodeURIComponent 之前一直不了解这两个的区别,现在知道了: encodeU ...
- escape,encodeURI,encodeURIComponent有什么区别?
一.escape escape是对字符串进行编码,使得可以在所有的电脑上可读,但是encodeURI和encodeURIComponent是对URL进行编码的.escape和后两者几乎没关系. esc ...
- url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介
转载地址:http://www.haorooms.com/post/js_escape_encodeURIComponent 引子 浏览器URl地址,上网一定会用到,但是浏览器地址有中文或者浏览器ur ...
- url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介【转】
引子 浏览器URl地址,上网一定会用到,但是浏览器地址有中文或者浏览器url参数操作的时候,经常会用到encodeURIComponent()和decodeURIComponent()以及encode ...
- js 编码解码 escape,encodeURI,encodeURIComponent
js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent 1 ...
- js 文字转码 escape,encodeURI,encodeURIComponent(marksheng)
js对文字进行转码的3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent 1. ...
- [转]js escape,encodeURI,encodeURIComponent
js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent 1 ...
- JS中URL中的特殊字符问题:escape,encodeURI,encodeURIComponent(转)
在使用url进行参数传递时,经常会传递一些中文名(或含有特殊字符)的参数或URL地址,在后台处理时会发生转换错误.在有些传递页面使用GB2312,而在接收页面使用UTF8,这样接收到的参数就可能会与原 ...
- URL转码escape() encodeURI() encodeURIComponent()
转:http://deony2jacob1314.iteye.com/blog/1753068 js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent, ...
- javascript URIError: malformed URI sequence 谈谈url编码 encodeURI encodeURIComponent和escape
一.案例描述 第一个页面,url传参数给第二个页面 <!DOCTYPE html> <html> <head> <meta http-equiv=" ...
最新文章
- php音频添加语音,PHP生成语音
- php 合并数组成父子关系,php - 将电子表格解析为PHP数组并返回具有父子关系的嵌套MLM表 - SO中文参考 - www.soinside.com...
- 小议H.264技术发展趋势
- Python基础:16面向对象概述
- python 单例类
- 软件无线电在4G技术的应用
- 基于Hexo+Node.js+github+coding搭建个人博客——基础篇
- 【安全】(三)Django之SQL注入防御
- ubuntu18.04 Nvidia 显卡的风扇调速及startx的后果 --转载
- 2021固态硬盘排行前十 十大固态硬盘排名
- python卷积神经网络预测股价_解读:一种基于CNN-LSTM混合神经网络的股价预测模型...
- hdu 5442 Favorite Donut 后缀数组
- 角度逼近圆弧插补法插补与仿真
- 【项目管理工具】—— Microsoft Office Project 介绍
- dns劫持是什么意思?常见的劫持有哪些?
- 夜神模拟器和安卓连接
- 去除bootstrap的table样式中单元格边框线
- SecureCRT连接后乱码问题!!!
- 工厂生产线设备数据采集方法
- oracle的后台进程杀掉会有什么影响
热门文章
- 智能导购系统设计与实现
- CI 框架邮件发送功能,以163为例
- 无需额外相机配件,在你的手机上利用佳能的Camera Connect APP实现延时摄影
- 银联宣布:无卡时代来了!有何神奇之处
- MySQL mdl导入_技术分享 | 深入理解 MySQL MDL Lock
- MDL(材质定义语言)
- Tekla Structures Design Suite安装步骤
- html5 video安排位置,js H5 video如何在关闭页面后记住播放位置,下次进入直接从该位置开始播放...
- 【迅为iMX6Q】开发板 u-boot 2020.04 SD卡 启动
- python windows系统下导入数据集的绝对路径问题