Different representations of Unicode characters
Unicode characters are represented in HTML, CSS, and JS in different ways, as described below.
The original is published here
CSS notation
First, a very common font icon code for bootstrap:
.glyphicon-home:before { content: "\e021";}
The code above is the e021
Unicode code for this character, which is 16 binary.
Grammar:
‘\ + 16进制的unicode编码‘
such as: ' \5b89 ' denotes the Chinese character "Ann":
<div class= "test" ></div><< Span class= "Hljs-name" >style> .test: Before {content: "\e021" </STYLE>
JS Representation method
Grammar:
‘\u + 16进制的unicode编码‘
Example:
// 如:‘\u5b89‘表示汉字“安”console.log(‘\u5b89‘); // 输出“安”
HTML representation method
HTML special Point, the use of 10 in the system , at first did not pay attention to this to make a day out not to be depressed for a long time.
Grammar:
‘&# + 10进制的unicode编码 + 英文分号;‘
such as & #23433;
(note, because the normal writing will be converted to Chinese characters, so I deliberately left a space in the middle to prevent conversion) 安
, the end of the semicolon after the test does not add, but it is better to add a bit.
<div> 这是unicode表示的字符“安”:& #23433;(这里故意留一空格防止转换)</div>
In addition, some special characters have other representations, which is often said html转义字符
, such as (because of the automatic conversion problem, here is represented by the picture):
The complete HTML escape character table can be found here:
http://tool.oschina.net/commons?type=2
Get Unicode encoding of Chinese characters
So, how do you know the Unicode encoding of a Chinese character? Very simple:
‘安‘.charCodeAt(); // 输出的 23433 就是汉字 安 的unicode编码,不过注意是10进制的String.fromCharCode(23433); // 输出 ‘安‘
Obtained 10 Unicode encoding, and then if you want to use JS and CSS inside, you need to use the toString(16)
turn 16 to do further processing.
var Unicode=‘\\U+charcodeat (). tostring (16) //output string: "\u8317" JSON. parse ( ' "' +unicode +//output Kanji: "Tea" eval ( "' +unicode+//or using eval parsing can also
HTML, CSS, JS different processing of Unicode characters