【发布时间】:2011-05-31 06:10:48
【问题描述】:
这两种方法中的哪一种应该用于编码 URL?
【问题讨论】:
-
一个主要区别是
encodeURI不会编码/所以:encodeURIComponent("ac/dc")=>ac%2Fdc和encodeURI("ac/dc")=>ac/dc -
这可能会有所帮助:
"encodeURIComponent() and encodeURI() encode a URI by replacing URL reserved characters with their UTF-8 encoding....They differ because encodeURI does not encode queryString or hash values...URLs do not allow many special characters, like spaces or slashes. However these special characters are part of life, so URL encoding was invented."Source -
另见标题为
encodeURIComponent differs from encodeURI as follows的特定部分:developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
标签: javascript