如何使用 jQuery 解码 URL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3803716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I decode a URL with jQuery?
提问by XMen
How can I decode a URL using jQuery? My url is
如何使用 jQuery 解码 URL?我的网址是
http%3A%2F%2Fdtzhqpwfdzscm.cloudfront.net%2F4ca06373624db.jpg
http%3A%2F%2Fdtzhqpwfdzscm.cloudfront.net%2F4ca06373624db.jpg
回答by Darin Dimitrov
Try the decodeURIComponentfunction:
试试decodeURIComponent函数:
var decodedUri = decodeURIComponent('http%3A%2F%2Fdtzhqpwfdzscm.cloudfront.net%2F4ca06373624db.jpg');
alert(decodedUri);
回答by Nick Craver
Use decodeURIComponent()
, for example:
使用decodeURIComponent()
,例如:
decodeURIComponent("http%3A%2F%2Fdtzhqpwfdzscm.cloudfront.net%2F4ca06373624db.jpg")
It's not jQuery specific, this is a base JavaScript function.
它不是特定于 jQuery 的,这是一个基本的 JavaScript 函数。
回答by Doug
You can simply call the standard javascript functions for encoding and decoding respectively.
您可以简单地分别调用标准的 javascript 函数进行编码和解码。
encodeURIComponent
decodeURIComponent
Enjoy!
享受!
回答by Jpsy
If you URL should also contain blanks encoded as '+', the following call will help (taken from https://stackoverflow.com/a/4458580/430742):
如果您的 URL 还应包含编码为“+”的空格,则以下调用将有所帮助(取自https://stackoverflow.com/a/4458580/430742):
decodeURIComponent((str+'').replace(/\+/g, '%20'))
回答by reko_t
decodeURIComponent('http%3A%2F%2Fdtzhqpwfdzscm.cloudfront.net%2F4ca06373624db.jpg')