您的位置:首页 > 其它

`encodeURI` 和 `encodeURIComponent`的区别

2015-12-08 12:29 232 查看

encodeURI
encodeURIComponent
的区别

encodeURI
加密一些URL中不允许的字符, 如空格等

var url = 'http://xx xxx/';
encodeURI(url);
// 输出: "http://xx%20xxx/"


encodeURIComponent
加密query string中的一些特殊字符

var url = 'http://xx xxx/';
encodeURIComponent(url);
// 输出: "http%3A%2F%2Fxx%20xxx%2F"


总结

当使用 http://www.judith.com?url=http://www.baidu.com 这种 query string 中带有 http:// 特殊字符时, 可以使用
encodeURIComponent
来进行加密
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  url