伪元素内容的数据内容中的Unicode [英] Unicode in data-content for pseudo element content
问题描述
我想使用JQuery将unicode放在data-content属性中,以便将其用于伪元素内容,但我找不到正确的格式。你如何显示unicode?暂停只显示▼
。
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", "▼");
推荐答案
使用<$ c $以此格式插入c> \ u 在Javascript中,表示字符串文字内的Unicode编号
Insert in this format, using the \u
that, in Javascript, denotes an Unicode number inside a string literal
$("a").attr ("data-content", "\u25BC");
来自 MDN Unicode转义文档 :
您可以在字符串文字,正则表达式和标识符中使用Unicode转义序列。转义序列由六个ASCII字符组成:\ u和四位十六进制数字。例如,\ u00A9代表版权符号。 JavaScript中的每个Unicode转义序列都被解释为一个字符。
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>
这篇关于伪元素内容的数据内容中的Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!