What is the JavaScript equivalent of C# Server.URLEncode?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
encodeURI()
http://xkr.us/articles/javascript/encode-compare/#ref-js-msdn
回答2:
No, encodeURIComponent()
exactly.
回答3:
There’s a wonderful article on xkr.us comparing javascript’s various escape functions. Do read it for details, but here’s a quick summery:
escape()
— don’t use: does not understand non-ASCII characters, and does not escape some important URI characters, such as+
.encodeURI()
— encodes an entire URI: as such, it leaves?
and&
unencoded.encodeURIComponent()
— encodes a component in a query string (this is usually the one you want, and appears to be the equivalent ofServer.URLEncode
).