- escape/unescape
- encodeURI/decodeURI
- encodeURIComponent/decodeURIComponent
1、escape/unescape
处理ASCII码表之外的字符
var url = "http://www.baidu.com?name=张三&age=23"; console.log(escape(url)); // http%3A//www.baidu.com%3Fname%3D%u5F20%u4E09%26age%3D23 var escapeUrl = "http%3A//www.baidu.com%3Fname%3D%u5F20%u4E09%26age%3D23"; console.log(unescape(escapeUrl)); // http://www.baidu.com?name=张三&age=23
2、encodeURI/decodeURI(用的较多)
处理unicode编码
var url = "http://www.baidu.com?name=张三&age=23"; console.log(encodeURI(url)); // http://www.baidu.com?name=%E5%BC%A0%E4%B8%89&age=23 var escapeUrl = "http://www.baidu.com?name=%E5%BC%A0%E4%B8%89&age=23"; console.log(decodeURI(escapeUrl)); // http://www.baidu.com?name=张三&age=23
3、encodeURIComponent/decodeURIComponent
var url = "http://www.baidu.com?name=张三&age=23"; console.log(encodeURIComponent(url)); // http%3A%2F%2Fwww.baidu.com%3Fname%3D%E5%BC%A0%E4%B8%89%26age%3D23 var escapeUrl = "http%3A%2F%2Fwww.baidu.com%3Fname%3D%E5%BC%A0%E4%B8%89%26age%3D23"; console.log(decodeURIComponent(escapeUrl)); // http://www.baidu.com?name=张三&age=23