这取决于你实际上想做什么.
encodeURI假定输入是一个完整的URI,其中可能包含一些需要编码的字符.
encodeURIComponent将以特殊的含义对所有内容进行编码,因此您可以将其用于URI的组件,例如
var world = "A string with symbols & characters that have special meaning?";
var uri = 'http://example.com/foo?hello=' + encodeURIComponent(world);