美文网首页
encodeURI 和 encodeURIComponent 区

encodeURI 和 encodeURIComponent 区

作者: ikonan | 来源:发表于2022-06-30 14:57 被阅读0次

encodeURI()和encodeURIComponent()都是Javascript中对URL编码的函数。

  • encodeURI()着眼于对整个URL进行编码,特殊含义的符号"; / ? : @ & = + $ , #“不进行编码
  • encodeURIComponent()对URL的组成部分进行个别编码,所以”; / ? : @ & = + $ , #"在这里是可以进行编码

测试

encodeURI("http://www.w3school.com.cn")  //  http://www.w3school.com.cn
encodeURIComponent("http://www.w3school.com.cn") // http%3A%2F%2Fwww.w3school.com.cn

总结

所以我一般进行设置时候,会在http路径采用encodeURI进行编码,但是在路径中携带的参数采用encodeURIComponent进行编码

相关文章

网友评论

      本文标题:encodeURI 和 encodeURIComponent 区

      本文链接:https://www.haomeiwen.com/subject/hlbfbrtx.html