encodeURI和encodeURIComponent的區別?

encodeURI方法不會對下列字符編碼 ASCII字母、數字、~!@#$&*()=:/,;?+'

encodeURIComponent方法不會對下列字符編碼 ASCII字母、數字、~!*()'

因此encodeURIComponent比encodeURI編碼的範圍更大。

實際例子來講,encodeURIComponent會把 http:// 編碼成 http%3A%2F%2F 而encodeURI卻不會。

若是你須要編碼整個 URL,而後須要使用這個URL,那麼用encodeURI。

當你須要編碼 URL中的參數的時候,那麼encodeURIComponent是最好方法
相關文章
相關標籤/搜索