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 + Space console.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)

最新文章

  1. 用javascript写星际飞机大战游戏
  2. 按钮点击,打开qq,用做联系客服
  3. nginx转发post消息成301了
  4. HBase的快照技术
  5. git 上传项目到github
  6. 会报编译器警告的Xcode 6.3新特性:Nullability Annotations
  7. GIT 专贴
  8. jquery 字符串转json
  9. Java中浮点数的基础知识
  10. LED汽车前大灯
  11. Oracle存储过程procedure
  12. 操作系统基本概念(内核态与用户态、操作系统结构)-by sixleaves
  13. Find the k-th Smallest Element in the Union of Two Sorted Arrays
  14. JavaScript看书笔记01
  15. V5.7_UTF8_SP1、SP2---任意前台用户登录(cookie伪造)
  16. 最短寻道优先算法----SSTF算法
  17. Chapter 4 Invitations——15
  18. 光盘yum源搭建
  19. oracle addm报告
  20. OpenCV2马拉松第2圈——读写图片

热门文章

  1. Django项目之【学员管理系统】
  2. 创建laravel项目
  3. Java for LeetCode 103 Binary Tree Zigzag Level Order Traversal
  4. TensorFlow框架(4)之CNN卷积神经网络详解
  5. g2o的一般过程
  6. 版本名称SNAPSHOT、alpha、beta、release、GA含义
  7. 游戏引擎基于Handle的资源管理
  8. Oracle 数据库SQL
  9. 配置 git 以ssh公钥访问github
  10. 基于深度学习的安卓恶意应用检测----------android manfest.xml + run time opcode, use 深度置信网络(DBN)