”http%3A%2F%2Fwww.baidu.com%2Fasd%3Fa%3D123”
这种特殊字符被转义成16进制的字符串
”%3A”表示冒号(百分号”%”是转义符, 相当于正则当中的反斜杠”/”)
可以用 encodeURIComponent和decodeURIComponent. 编码和转码
encodeURIComponent是转义字符串,
decodeURIComponent是解析字符串.
当遇到上面的字符串时, 直接使用 decodeURIComponent解析, 而解析结果也会变成我们想要的字符串:”http://www.baidu.com/asd?a=123”
decodeURIComponent(URIstring)
URIstring 的副本,其中的十六进制转义序列将被它们表示的字符替换。
decodeURIComponent(“http%3A%2F%2Fwww.baidu.com%2Fasd%3Fa%3D123”)
得到”http://www.baidu.com/asd?a=123”
而decodeURI和encodeURI, 跟前面的类似, 只不过不会转义特殊字符