在我的AngularJS脚本中,我使用VanillaJS decodeURIComponent
转换部分URI,如下所示:
var someVar = decodeURIComponent(uristring); //uristring = Zao0%2B1
但是当使用someVar
输出alert()
或放入输入字段时,我会继续Zao0%2B1
而不是Zao0+B1
作为输出。发生了什么事?
答案 0 :(得分:3)
您的输入看起来与预期结果不符。
如果我们获取预期结果并对其进行编码,则返回的值不同于您用作输入的值
var str = "Zao0+B1"// your expected output
// encode it
var encoded = encodeURIComponent(str);
console.log(encoded);// "Zao0%2BB1" - differs from your input
// decode it
var result = decodeURIComponent(encoded);
console.log(result); // "Zao0+B1" - same as original and as per expected result in question