JS encodeURI()和encodeURIComponent()区别

encodeURI():对URI中的特殊字符不进行编码(:/?)

encodeURIComponent():所有非标准字符进行编码

 

var str = "http://www.baidu.com/";
alert(encodeURI(str));//http://www.baidu.com/
//http%3A%2F%2Fwww.baidu.com%2F
alert(encodeURIComponent(str));

 

你可能感兴趣的:(JS encodeURI()和encodeURIComponent()区别)