Javascript用空格替换查询字符串+

Bru*_*ark 4 javascript url decode query-string

我抓住查询字符串参数并尝试这样做:

var hello = unescape(helloQueryString); 
Run Code Online (Sandbox Code Playgroud)

它返回:

this+is+the+string
Run Code Online (Sandbox Code Playgroud)

代替:

this is the string
Run Code Online (Sandbox Code Playgroud)

如果%20在那里,那么效果很好,但它是+.有没有什么方法可以正确解码它们,所以它们+符号会变成空格?

谢谢.

CMS*_*CMS 7

decodeURIComponent函数将正确处理解码:

decodeURIComponent("this%20is%20the%20string"); // "this is the string"
Run Code Online (Sandbox Code Playgroud)

看看以下文章: