escape、encodeURI和encodeURIComponent区别

1. escape是给字符串编码,没在实际场景遇到过

2.对url变化或url的参数编码,经常用到encodeURI和encodeURIComponent, 区别是编码范围不同:

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

encodeURIComponent方法不会对下列字符编码 ASCII字母、数字、~!*()'
 
3. 应用:( 完整url组成:href = protocol:host:port/path?query#hash )
encodeURIComponent适用于对url的query编码:尤其是url参数里有/:中文等字符,那是一定要用encodeURIComponent编码的。
encodeURI适用于对url的protocol:host:port/path编码,编码后的url不会影响url的识别性,用浏览器依然可以识别打开。
原文地址:https://www.cnblogs.com/liyongquan/p/8496113.html