地址转码方式

encodeURIComponent转码  decodeURIComponent反转码

let a = encodeURIComponent("http://www.w3school.com.cn/Myfirst/!@#$%$^&777的萨芬")
console.log(a)  //  http%3A%2F%2Fwww.w3school.%20com.cn%2FMyfirst%2F!%40%23%24%25%24%5E%26777%E7%9A%84%E8%90%A8%E8%8A%AC
let b = decodeURIComponent(a)
console.log(b)  //http://www.w3school.com.cn/Myfirst/!@#$%$^&777的萨芬

encodeURI转码  decodeURI反转码

let a1 = encodeURI("http://www.w3school.com.cn/Myfirst/!@#$%$^&777的萨芬")
console.log(a1)  //  http://www.w3school.%20com.cn/Myfirst/!@#$%25$%5E&777%E7%9A%84%E8%90%A8%E8%8A%AC
let b1 = decodeURI(a1)
console.log(b1)  //  http://www.w3school.com.cn/Myfirst/!@#$%$^&777的萨芬

两者的区别

encodeURIComponent 和 encodeURI的区别
根据我的初步理解,encodeURIComponent 转码除了英文字母、数字以及'.'以外的所有字符,encodeURI则转码比较少,像!@#$%^等这些常用字符不会转码,其他的和encodeURIComponent一样
(只测试了一部分,猜测是这样子的,更多的自己去尝试)
原文地址:https://www.cnblogs.com/Simple-and-complex/p/11987550.html