js 对url字符转译全解

1.js 对url进行字符解码设计到3个方法

escape , encodeURI , encodeURIComponent

eg:

var url='http://baidu.com';
encodeURIComponent(url);   //  "http%3A%2F%2Fbaidu.com"

对应的三个解码方法

unescape , decodeURI , decodeURIComponent

eg:

var url="http%3A%2F%2Fbaidu.com";
decodeURIComponent(url);    //  "http://baidu.com"

2.进行url跳转可以整体使用 encodeURI
eg:location.href=encodeURI(http://cang.baicu.com/do/s?word=百度&ct=21);
 
3.js 使用数据时可以使用escape 
例如 收索 
原文地址:https://www.cnblogs.com/zerohu/p/5101671.html