encodeURI and decodeURI are used in pairs, because if there are Chinese characters in the address bar of the browser, unexpected errors may occur, so encodeURI can convert non-English characters into English encoding, and decodeURI can be used to restore the characters back
1. Basic concepts
encodeURI and decodeURI are used in pairs, because if there are Chinese characters in the address bar of the browser, unexpected errors may occur, so encodeURI can convert non-English characters into English encoding, and decodeURI can be used to encode The characters are restored. The encodeURI method does not encode the following characters: ":", "/", ";" and "?", which the encodeURIComponent method can encode.
The decodeURI() method is equivalent to java.net.URLDecoder.decode(URIString, "UTF-8"); the
encodeURI() method is equivalent to java.net.URLEncoder.encode(URIString, "UTF-8");
encodeURI and decodeURI are used in pairs, because if there are Chinese characters in the address bar of the browser, unexpected errors may occur, so encodeURI can convert non-English characters into English encoding, and decodeURI can be used to encode The characters are restored. The encodeURI method does not encode the following characters: ":", "/", ";" and "?", which the encodeURIComponent method can encode.
The decodeURI() method is equivalent to java.net.URLDecoder.decode(URIString, "UTF-8"); the
encodeURI() method is equivalent to java.net.URLEncoder.encode(URIString, "UTF-8");
<script type="text/javascript"> var uriStr = "http://www.baidu.com?name=张三&num=001 zs"; var uriec = encodeURI(uriStr); document.write("encoded" + uriec); var uridc = decodeURI (uriec); document.write("decoded" + uridc); </script>Encoded http://www.baidu.com?name=%E5%BC%A0%E4%B8%89&num=001%20zs