【发布时间】:2012-08-16 01:47:07
【问题描述】:
这应该是一项简单的任务,但我似乎找不到解决方案。
我有一个基本字符串作为查询字符串参数传递,如下所示:This+is+a+message+with+spaces。我想使用 JavaScript 将该参数解码为This is a message with spaces,但我似乎无法对其进行解码。
我尝试了decodeURI('This+is+a+message+with+spaces'),但结果仍然包含+ 符号。
【问题讨论】:
-
URL需要编码才能解码;)
-
Locrizak,
decodeURIComponent('This+is+a+message+with+spaces')仍然返回This+is+a+message+with+spaces。encodeURIComponent('This+is+a+message+with+spaces')返回This%2Bis%2Ba%2Bmessage%2Bwith%2Bspaces。我一定错过了什么,因为我没有看到这是如何解决我的问题的。
标签: javascript html forms decoding url-parameters