[乐意黎原创]JS中url转义escape()、encodeURI()和decodeURI()函数说明
来源:互联网 发布:淘宝外卖怎么投诉商家 编辑:程序博客网 时间:2024/05/19 18:17
在JS中, escape()除了 ASCII 字母、数字和特定的符号外,对传进来的字符串全部进行转义编码,如对URL编码,最好不要使用此方法。
而encodeURI() 用于编码整个URI,因为URI中的合法字符都不会被编码转换。
encodeURIComponent方法在编码单个URIComponent(指请求参数)应当是最常用的,它可以讲参数中的中文、特殊字符进行转义,而不会影响整个URL。
请注意 encodeURIComponent() 函数 与 encodeURI() 函数的区别之处,
前者假定它的参数是 URI 的一部分(比如协议、主机名、路径或查询字符串)。
因此 encodeURIComponent() 函数将转义用于分隔 URI 各个部分的标点符号。
一、encodeURI() //转义一个URI中的字符
语法:encodeURI(uri) //这个在编码不同的AJAX请求时,解决中文乱码问题经常用到。
var str1 = "aerchi, hello world. /"; var str2 = encodeURI(str1); document.write(str2); //aerchi,%20hello%20world.%20/
二、decodeURI() //解码一个URI中的字符
语法:decodeURI(uri)
var str1 = "aerchi, hello world. /"; var str2 = encodeURI(str1); document.write(str2); //aerchi,%20hello%20world.%20/ var str3 = decodeURI(str2); document.write("<br/>" + str3) //aerchi, hello world. /
三、encodeURIComponent() //转义URI组件中的字符
var str1 = "aerchi, hello world. /"; var str2 = encodeURIComponent(str1); document.write(str2); //aerchi%2C%20hello%20world.%20%2F
四、decodeURIComponent() //解码一个URI组件中的字符
var str1 = "aerchi, hello world. /"; var str2 = encodeURIComponent(str1); document.write(str2); //aerchi%2C%20hello%20world.%20%2F var str3 = decodeURIComponent(str2); document.write("<br/>" + str3) //aerchi, hello world. /
五、escape() //编码一个字符串
语法:escape(value);
var str = "aerchi, hello world. /"; var str1 = escape(str); document.write(str1); //aerchi%2C%20hello%20world.%20/
六、unecape() //解码一个由escape()函数编码的字符串
window.onload = function () { var str = "aerchi, hello world. /"; var str1 = escape(str); document.write(str1); //aerchi%2C%20hello%20world.%20/ var str2 = unescape(str1); alert(str2); //弹出: aerchi, hello world. / }
哈哈, 验证完毕.
乐意黎
阅读全文
0 0
- [乐意黎原创]JS中url转义escape()、encodeURI()和decodeURI()函数说明
- javascript之url转义escape()、encodeURI()和decodeURI()
- javascript之url转义escape()、encodeURI()和decodeURI()
- javascript中encodeURI和decodeURI方法转译URL
- js中的编码解码--escape/unescape、encodeURI/decodeURI 、encodeURIComponent/decodeURIComponent
- Js中escape(),encodeURI()和encodeURIComponent()比较
- Js中escape(),encodeURI()和encodeURIComponent()
- js中escape,encodeURI和encodeURIComponent区别
- escape()、encodeURI()、decodeURI()、encodeURIComponent()、decodeURIComponent()
- url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介
- url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介
- url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介
- url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介
- url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介
- url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介
- url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介
- javascript中escape()、unescape()、encodeURI()、encodeURIComponent()、decodeURI()、decodeURIComponent()比较
- javascript中escape()、unescape()、encodeURI()、encodeURIComponent()、decodeURI()、decodeURIComponent()比较
- Linux mysql 安装
- leetcode 101. Symmetric Tree(C语言,二叉树,递归,判对称性)30
- 数据库三大范式详解
- IDEA配置Tomcat及项目
- IIS上配置CGI
- [乐意黎原创]JS中url转义escape()、encodeURI()和decodeURI()函数说明
- Warning: require(): open_basedir restriction in effect.
- 一道状压dp水题
- android中 创建 删除 清空 SharedPreferences
- MYSQL启动报错故障及解决
- 关于 make -j4
- 遇到Class path contains multiple SLF4J bindings.该如何解决?
- activiti实战五(我的流程)
- Unity富文本详解