Introduction to 16 characters in JavaScript _javascript tips

Source: Internet
Author: User
Some time ago read "JavaScript Advanced program Design" finally found a little introduction:
\xnn a character (n:0-f) expressed in hexadecimal code nn
\UNNN A Unicode character (n:0-f) in hexadecimal code

Today because one of their own needs to know the hexadecimal representation of some Chinese characters, so you write two methods, you can convert the text to a 16-way representation, you can convert the 16-code into Chinese characters. The method is as follows:

Copy Code code as follows:

Convert Text to 16
function Texttosix (str) {
return Escape (str). replace (/%/g, function () {
return "\";
}). toLowerCase ();
}
To represent a 16 binary as text
function Sixtotext (str) {
return unescape (str);
}


Online Demo Code:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <title></title> <style type=" Text/css "> table {border:1px solid #12aded; Border-collapse:collapse; The table TR {border:1px solid #12aded; Border-collapse:collapse; Table TR td {BORDER:1PX solid #12aded; Border-collapse:collapse; </style> </pead> <body> <table cellpadding= "0" cellspacing= "0" border= "0px" > <tr> &l t;td> <textarea id= "Tbvalue" rows= "8" cols= "" ></textarea> </td> <td> <input type= "Butt" On "value=" to convert text to 16 "onclick=" Show () "/> </td> </tr> <tr> <td> <textarea id=" Tbresult " Rows= "8" cols= "a" ></textarea> </td> <td> <input type= "button" value= "converts 16 to text" onclick= "sh Ow2 () "/> </td> </tr> </table> <script type= "Text/javascript" >//Convert Text to 16 function texttosix (str) {return escape (str). replace (/%/g , function () {return "\"; }). toLowerCase (); ///16 is represented as literal function sixtotext (str) {return unescape (str); Function Show () {var tbvalue = document.getElementById ("Tbvalue"); var tbresult = document.getElementById ("Tbresult"); Tbresult.value = Texttosix (Tbvalue.value); } var Tempvalue; function Show2 () {var tbvalue = document.getElementById ("Tbvalue"); var tbresult = document.getElementById ("Tbresult"); Tempvalue = Tbvalue.value; Tbvalue.value = ""; SetTimeout (' Tbvalue.value=sixtotext (tempvalue); ', 500); } </script> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
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.