-2

我有一串 url 编码的字符。

想知道是否有一个 javascript 函数可以用普通字符串字符替换所有 url 编码的字符。

我知道我可以使用替换功能,但它只替换一个特定字符,而不是一次全部替换

例如,我正在寻找一个函数来替换此字符串中的所有 url 编码字符:

string urlEncoded = '1%20day%20%40work!%20Where%20are%20you%3F'

给我这个字符串:

string replaced = '1 day @ work! Where are you?'

多谢

4

4 回答 4

0
string replaced = decodeURIComponent(urlEncoded);

还有只是decodeURI,但这不能处理“特殊”字符,例如 & ?!# ETC

于 2012-07-21T09:20:00.850 回答
0

为此目的使用 decodeURIComponent(string)。

string urlEncoded = '1%20day%20%40work!%20Where%20are%20you%3F';
string replaced = decodeURIComponent(urlEncoded);
alert(replaced);

更多信息在这里:https ://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/decodeURIComponent

于 2012-07-21T09:20:34.767 回答
0

使用 decodeURIComponent(urlEncoded)

于 2012-07-21T09:20:42.987 回答
-1

你正在寻找unescape

var decoded = unescape(urlEncoded);
于 2012-07-21T09:20:32.963 回答