问题
I would like to put unicode in the data-content attribute using JQuery so as to use it for pseudo element content, but I can't find the right format. How do you display unicode? The fallowing just displays ▼
.
a::after
{
content: attr(data-content);
}
<a href="...">...</a>
$("a").attr ("data-content", "▼");
回答1:
Insert in this format, using the \u
that, in Javascript, denotes an Unicode number inside a string literal
$("a").attr ("data-content", "\u25BC");
From MDN Unicode escape docs:
You can use the Unicode escape sequence in string literals, regular expressions, and identifiers. The escape sequence consists of six ASCII characters: \u and a four-digit hexadecimal number. For example, \u00A9 represents the copyright symbol. Every Unicode escape sequence in JavaScript is interpreted as one character.
$("a").attr ("data-content", "\u25BC");
a::after
{
content: attr(data-content);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<a href="...">...</a>
来源:https://stackoverflow.com/questions/26025774/unicode-in-data-content-for-pseudo-element-content