url编码函数encodeURI和encodeURIComponent
生活随笔
收集整理的這篇文章主要介紹了
url编码函数encodeURI和encodeURIComponent
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
var url = "http://www.wrox.com/illegal value.html#start";
encodeURIComponent(url)? //"http%3A%2F%2Fwww.wrox.com%2Fillegal%20value.html%23start"
encodeURI(url)? ?//"http://www.wrox.com/illegal%20value.html#start"
?
記住2種特殊字符,一種,瀏覽器無法識別的特殊字符,如空格、中文。第二種,屬于url的特殊字符,如/、//、# 、&等。
encodeURI方法只把第一種特殊字符轉義,而encodeURIComponent方法會把兩種特殊字符都轉義。如果我們需要把url作為參數傳給服務器,是要用encodeURIComponent方法的。
?
encodeURIComponent() 函數可把字符串作為 URI 組件進行編碼。
decodeURIComponent() 解碼
encodeURI 編碼
decodeURI 解碼
轉載于:https://www.cnblogs.com/shuihanxiao/p/9909467.html
總結
以上是生活随笔為你收集整理的url编码函数encodeURI和encodeURIComponent的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于安装office软件时和visio软
- 下一篇: VS2015配置环境支持opencv3库