Unicode in data-content for pseudo element content

偶尔善良 提交于 2019-12-10 20:53:27

问题


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", "&#x25BC;");

回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!