4
我使用serialize()
来获取表单值,为了获取值我分割序列化的字符串,但值是uri编码,像'@'被替换为'%40',我用decodeURIComponent()
来解码,问题看起来像解决了,但我仍然把空格换成'+'符号。可以使用string.replace()
,但它会替换字符串中我的合法'+'符号。如何实现它?反序列化表值
我使用serialize()
来获取表单值,为了获取值我分割序列化的字符串,但值是uri编码,像'@'被替换为'%40',我用decodeURIComponent()
来解码,问题看起来像解决了,但我仍然把空格换成'+'符号。可以使用string.replace()
,但它会替换字符串中我的合法'+'符号。如何实现它?反序列化表值
如果字符串中有合法的+
,则它将被编码为%2B
。因此,在对字符串进行调用decodeURIComponent()
之前,用空格替换表示字符串中空格的所有+
,然后调用decodeURIComponent()
来解码字符串。
使用此代码
var str = "%4Bseri%2Balized+String+plus"
str = str.replace(/\+/g, " ");
str = decodeURIComponent(str);
alert(str);