JavaScript encoding and decoding method (decodeURIComponent)

Source: Internet
Author: User

JavaScript (Urldecodedecodeuricomponent ()) This function name is too often, the individual really do not understand, after all, JS system functions are many, it is easy to miss. Trouble found this function by accident!
Encoding function: encodeURIComponent ()
decoding function: decodeURIComponent ()
decodeURIComponent () syntax
decodeURIComponent (uristring)
Parameters: (uristring) required. A string that contains the encoded 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.

Example:

The code is as follows Copy Code
<script type= "Text/javascript" >
<! [cdata[
var test1= "annoyance";

var test2= "%E7%83%A6%E6%81%BC";

document.write ("code (formerly =" +test1+ "):" +encodeuricomponent (test1));

document.write ("Decoding (formerly =" +test2+ "):" +decodeuricomponent (test2));
]]>
</script>

Results:
Coding (original = annoyance):%E7%83%A6%E6%81%BC
Decoding (original =%E7%83%A6%E6%81%BC): Annoyance
Note: The test passes in the UTF-8 coding environment.

Related Article

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.