What is the JavaScript equivalent of C# Server.URL

2020-07-05 05:02发布

What is the JavaScript equivalent of C# Server.URLEncode?

3条回答
ら.Afraid
2楼-- · 2020-07-05 05:48

No, encodeURIComponent() exactly.

查看更多
看我几分像从前
4楼-- · 2020-07-05 06:02

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 of Server.URLEncode).
查看更多
登录 后发表回答