encodeURIComponent和encodeURI的区别

相同点:   1、encodeURIComponent()和enCodeURI()方法都可以对URI进行编码,以便发送给浏览器,因为有效URI不能包含某些字符,例如空格等。通过这两个方法对URI进行编码,它们用特殊的UTF-8编码替换所有无效的字符,从而能够让浏览器识别

不同点:

1、encodeURI()主要用于整个URI,它不会对本身属于URI的特殊字符进行编码例如:

ASCII字母、数字、~!@#$&*()=:/,;?+'

2.encodeURIComponent()可用于编码URI中的参数,encodeURIComponent方法不会对下列字符编码:

ASCII字母、数字、~!*()'

3. encodeURIComponent解码的范围更广,encodeURI主要是对空格进行编码

4.encodeURI通过decodeURI进行解码,encodeURLComponent通过decodeURIComponent进行解码

你可能感兴趣的:(encodeURIComponent和encodeURI的区别)