JavaScript decodeURI () differs from decodeuricomponent () __java

Source: Internet
Author: User
Turn from: http://blog.csdn.net/maxracer/article/details/7030903

decodeURI () Definition and usage: the decodeURI () function decodes the URI encoded by the encodeURI () function.
Syntax: decodeURI (uristring)
Parameter description: Uristring required, a string containing the URI group to decode or other text to decode.
Return value: A copy of the uristring in which the hexadecimal escape sequence is replaced by the character they represent.

decodeURIComponent () Definition and usage: the decodeURIComponent () function decodes the URI encoded by the encodeURIComponent () function.
Syntax: decodeURIComponent (uristring)
Parameter description: Uristring required, a string containing the decoded URI component or other text to decode.
Return value: A copy of the uristring in which the hexadecimal escape sequence is replaced by the character they represent.

<body>
<script type= "Text/javascript" >
var test = "Http://www.test.com/My test/";

var test1 = encodeURI (test);
var test2 = decodeURI (test1);
var test3 = encodeuricomponent (test);
var test4 = decodeuricomponent (TEST3);

document.write (test1 + "<br/>");
document.write (test2 + "<br/>");
document.write (test3 + "<br/>");
document.write (test4 + "<br/>");
</script>
</body>

Run Result:
http://www.test.com/My%20test/
http://www.test.com/My test/
http%3a%2f%2fwww.test.com% 2fmy%20test%2f
http://www.test.com/My test/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.