Fork me on GitHub

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 
例如 收索 
posted @ 2016-01-05 11:09  明天后浪  阅读(2139)  评论(0编辑  收藏  举报