`
nianshi
  • 浏览: 406871 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

encodeURI和encodeURIComponent

 
阅读更多

encodeURI和encodeURIComponent
window.encodeURI函数用来编码一个URL,但是不会对以下字符进行编码:“:”, “/”, “;”, “?”.
window.encodeURIComponent则会对上述字符进行编码。
我们通过一个例子来说明:

?
1
2
'index.jsp?page=' +encodeURI( '/page/home.jsp' );  // "index.jsp?page=/page/home.jsp"
'index.jsp?page=' +encodeURIComponent( '/page/home.jsp' );  // "index.jsp?page=%2Fpage%2Fhome.jsp"

因此,在对URL进行编码时我们经常会选择 encodeURIComponent。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics