`encodeURI` 和 `encodeURIComponent`的区别

来源:互联网 发布:淘宝纯棉四件套 编辑:程序博客网 时间:2024/06/04 18:31

encodeURIencodeURIComponent的区别

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 来进行加密

0 0
原创粉丝点击