encodeURI和encodeURIComponent的区别?

encodeURI方法不会对下列字符编码 ASCII字母、数字、~!@#$&*()=:/,;?+'

encodeURIComponent方法不会对下列字符编码 ASCII字母、数字、~!*()'

所以encodeURIComponent比encodeURI编码的范围更大。

实际例子来说,encodeURIComponent会把 http:// 编码成 http%3A%2F%2F 而encodeURI却不会。

如果你需要编码整个 URL,然后需要使用这个URL,那么用encodeURI。

当你需要编码 URL中的参数的时候,那么encodeURIComponent是最好方法

猜你喜欢

转载自www.cnblogs.com/yxdlm/p/10929119.html