我正在获取查询字符串参数并尝试这样做:
var hello = unescape(helloQueryString);
它返回:
this+is+the+string
代替:
this is the string
如果 %20 在那里,效果很好,但它是 +。有什么方法可以正确解码这些符号,使它们的 + 符号变为空格?
谢谢。
最佳答案
decodeURIComponent
函数将正确处理解码:
decodeURIComponent("this%20is%20the%20string"); // "this is the string"
看看下面的文章:
关于Javascript 用空格替换查询字符串 +,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2918336/