encodeURIComponent() - 2019-09-17

encodeURIComponent() 函数可把字符串作为 URI 组件进行编码。encodeURIComponent(URIstring)

encodeURI()不会对本身属于URI的特殊字符进行编码,例如冒号、正斜杠、问号和井字号;而encodeURIComponent()则会对它发现的任何非标准字符进行编码。

使用encodeURI()编码后的结果是除了空格之外的其他字符都原封不动,只有空格被替换成了%20。而encodeURIComponent()方法则会使用对应的编码替换所有非字母数字字符。

encodeURI()对基础URL进行编码,encodeURIComponent()对查询字符串参数进行编码

所以这就是对整个URI使用encodeURI(),对附加在现有URI后面的字符串使用encodeURIComponent()的原因。

decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。decodeURIComponent(URIstring)

你可能感兴趣的:(encodeURIComponent() - 2019-09-17)