首页 技术 正文
技术 2022年11月15日
0 收藏 683 点赞 3,386 浏览 1347 个字

encodeURI、decodeURI

encodeURI、decodeURI 对字符转义;不替换特殊字符有18个、(大小写)字母、数字。

替换目标

将字符替换为 HTML URL编码

替换范围

A-Z a-z 0-9 – _ . ! ~ * ‘ ( ) / ? : @ & = + $ #   不替换,其他都替换

    

encodeURI("ABC abc 123")     //ABC%20abc%20123
decodeURI("ABC%20abc%20123") //ABC abc 123

encodeURIComponent、decodeURIComponent:

对特殊字符转码,

    替换范围:  A-Z a-z 0-9 – _ . ! ~ * ‘ ( )   不替换,其他都替换

    

var set1 = ";,/?:@&=+$";
var set2 = "-_.!~*'()";
var set3 = "#";
var set4 = "ABC abc 123";console.log(encodeURIComponent(set1)); //%3B%2C%2F%3F%3A%40%26%3D%2B%24
console.log(encodeURIComponent(set2)); // -_.!~*'()
console.log(encodeURIComponent(set3)); // %23
console.log(encodeURIComponent(set4)); // ABC%20abc%20123 (the space gets encoded as %20)

encodeURIComponent和encodeURI的区别

  范围区别:encodeURIComponent的替换字符 > encodeURI的替换字符

  1.encodeURIComponent会替换: / ? : @ & = + $ #

  2.encdoeURI不会替换: / ? : @ & = + $ #

  

var set1 = ";,/?:@&=+$";  // Reserved Characters
var set2 = "-_.!~*'()"; // Unescaped Characters
var set3 = "#"; // Number Sign
var set4 = "ABC abc 123"; // Alphanumeric Characters + Spaceconsole.log(encodeURI(set1)); // ;,/?:@&=+$
console.log(encodeURI(set2)); // -_.!~*'()
console.log(encodeURI(set3)); // #
console.log(encodeURI(set4)); // ABC%20abc%20123 (the space gets encoded as %20)console.log(encodeURIComponent(set1)); // %3B%2C%2F%3F%3A%40%26%3D%2B%24
console.log(encodeURIComponent(set2)); // -_.!~*'()
console.log(encodeURIComponent(set3)); // %23
console.log(encodeURIComponent(set4)); // ABC%20abc%20123 (the space gets encoded as %20)
上一篇: iscsi使用教程
下一篇: 3dmax视频
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,490
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,905
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,738
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,491
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,129
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,292