如何在JavaScript中解码字符串?
这对我不起作用:如何在JavaScript中解码字符串?,javascript,Javascript,这对我不起作用: var foo = "Collection%3A 9 Bad Interviews With Former GOP Presidential Candidates"; console.log(decodeURI(foo)); 它输出: Collection%3A 9 Bad Interviews With Former GOP Presidential Candidates 这是不正确的,如果您在以下站点上输入foo字符串: 它显示了正确的输出,即: Collectio
var foo = "Collection%3A 9 Bad Interviews With Former GOP Presidential Candidates";
console.log(decodeURI(foo));
它输出:
Collection%3A 9 Bad Interviews With Former GOP Presidential Candidates
这是不正确的,如果您在以下站点上输入foo字符串:
它显示了正确的输出,即:
Collection: 9 Bad Interviews With Former GOP Presidential Candidates
如何正确解码字符串?使用:
decodeURI
有一些问题,正如您所看到的<代码>解码组件是此项工作的最佳实践工具。如何:
unescape("Collection%3A 9 Bad Interviews With Former GOP Presidential Candidates")
URIdecodeURI()
expected实际上如下所示:
收集:%209%20错误%20与%20前任%20共和党%20总统%20候选人的面试%20
看看我的意思。您需要的是。和之间的差异
主要区别是:因此,在您的情况下,工作是否可能重复,我不建议使用这些:
unescape("Collection%3A 9 Bad Interviews With Former GOP Presidential Candidates")