对 String 进行编码。
ASCII字母、数字、@*/+
不会被编码
对 URL 进行编码。
不会编码的范围:
ASCII字母、数字、~!@#$&*()=:/,;?+'
encodeURI("http://www.cnblogs.com/season-huang/some other thing");
// "http://www.cnblogs.com/season-huang/some%20other%20thing";
对 URL 进行编码。
不会编码的范围:
ASCII字母、数字、~!*()'
encodeURIComponent("http://www.cnblogs.com/season-huang/some other thing");
// "/" 也会被编码,整个 URL 都无法使用了
// "http%3A%2F%2Fwww.cnblogs.com%2Fseason-huang%2Fsome%20other%20thing"
因为参数中如果有 "/" 也会被编码,更完善。