Home > Web Front-end > JS Tutorial > body text

JavaScript中的16进制字符介绍_javascript技巧

WBOY
Release: 2016-05-16 18:01:13
Original
1485 people have browsed it

前段时间看《JavaScript高级程序设计》终于找到了一点点介绍:
\xnn 以十六进制代码nn表示的一个字符(n:0-F)
\unnn以十六进制代码表示的一个Unicode字符(n:0-F)

今天由于一个自己的一个需求需要知道一些汉字的十六进制表示,因此自己写了两个方法,可以将文字转换为16进制的表示形式,也可以将16进制代码转换回汉字。方法如下:

复制代码 代码如下:

//将文字转换为16进制
function textToSix(str) {
return escape(str).replace(/%/g, function () {
return "\\";
}).toLowerCase();
}
//将16进制表示为文字
function sixToText(str) {
return unescape(str);
}


在线演示代码:

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!