2010-05-27 20 views
4

我抓住了查詢字符串參數,並試圖做到這一點替換查詢字符串+:的Javascript空間

var hello = unescape(helloQueryString); 

,並返回:代替

this+is+the+string 

this is the string 

如果%20在那裏,但它是+的,效果很好。任何方式來正確解碼這些他們+符號移動到空格?

謝謝。

回答

0

添加此行之後會工作:

hello = hello.replace('+', ' '); 
+3

hello = hello.replace(/ \ +/g,'')如果您預計單詞之間會有更多空格。 – 2010-05-27 03:51:08

+0

這樣做會不會更好(這種方式你不會得到巨大的空白空白):hello.replace(/ \ ++ /,'') – 2010-05-27 03:56:31