Difference between decodeURI () and decodeURIComponent () in JS, decodeuricomponent
Abstract:This article introduces two decoding functions: decodeURI () and decodeURIComponent (). These two functions can decrypt the cryptographic strings generated by a specific function, it can generate undecrypted strings, which is more practical. below
This article introduces two decoding functions: decodeURI () and decodeURIComponent (). These two functions can decrypt the cryptographic strings generated by a specific function, you can generate undecrypted strings, which are more practical. Let's take a look at the usage and examples of these two functions, and you will use them:
DecodeURI () Definition and usage: The decodeURI () function can decode the URI encoded by the encodeURI () function.
Syntax: decodeURI (URIstring)
Parameter description: Required for URIstring. A string containing the URI or other text to be decoded.
Returned value: a copy of URIstring. The hexadecimal escape sequence is replaced by the characters they represent.
DecodeURIComponent () Definition and usage: The decodeURIComponent () function can decode the URI encoded by the encodeURIComponent () function.
Syntax: decodeURIComponent (URIstring)
Parameter description: Required for URIstring. A string containing the URI component or other text to be decoded.
Returned value: a copy of URIstring. The hexadecimal escape sequence is replaced by the characters they represent.
Instance:
[Html]View plaincopy
- <Html>
- <Body>
- <Script type = "text/javascript">
- Var test1 = "http://www.wljcz.com/My first /";
- Var nn = encodeURI (test1 );
- Var now = decodeURI (test1 );
- Document. write (nn + "<br/> ");
- Document. write (now );
- Var test1 = "http://www.wljcz.com/My first /";
- Var bb = encodeURIComponent (test1 );
- Var nnow = decodeURIComponent (bb );
- Document. write (bb + "<br/> ");
- Document. write (nnow );
- </Script>
- </Body>
- </Html>
The running result is:
Http://www.wljcz.com/My%20first/
Http://www.wljcz.com/My first/
Http % 3A % 2F % 2Fwww.wljcz.com % 2FMy % 20 first % 2F
Http://www.wljcz.com/My first/