urllib.quote_plus()在JavaScript中等效

Omi*_*uri 6 javascript python urllib urlencode

试图从Python中移植一段代码:

my_input = "this&is£some text"
encoded_input = urllib.quote_plus(str(my_input))
Run Code Online (Sandbox Code Playgroud)

...到JavaScript:

var my_input = "this&is£some text";
encoded_input = encodeURIComponent(my_input);
Run Code Online (Sandbox Code Playgroud)

细微差别在于urllib.quote_plus()将空格转换+%20 (链接).只是想知道是否有人可以提供任何想法.目前正在与...

var my_input = "this&is£some text";
encoded_input = encodeURIComponent(my_input).replace(/%20/g,'+');
Run Code Online (Sandbox Code Playgroud)

adr*_*anp 3

在 Python 代码中使用urllib.quote()而不是。quote_plus()如果更改 Python 代码不是解决方案,那么您选择替换为的%20方法+无论如何都是首选方法(参考,描述中的第二段)。