
例如:“在地板上打滚大笑”会在浏览器中显示一个正方形。我怎么才能让真正的表情符号不像suqare那样出现呢?
String.fromCodePoint(0x1F923)
这是一张arups jsbin的照片,如下所示:

发布于 2018-08-20 04:36:09
这个例子适用于我在Firefox61上的工作。输出为:

在Google Chrome上,我使用的是:

现在,尝试运行以下代码片段:
document.querySelector('.output').textContent = String.fromCodePoint(0x1F923);
console.log(String.fromCodePoint(0x1F923));<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<p class='output'></p>
</body>
</html>
如果你仍然看到那个正方形,请检查你的浏览器的编码和你的默认字体。并检查它是否支持表情符号,就像在我的Google Chrome上没有渲染它。
因此,您可能需要使用像Twitter's Twemoji这样的第三方JavaScript库
// I got the Unicode for that emoji(1F602) from www.unicode.org/emoji/charts/full-emoji-list.html
document.querySelector('.output').innerHTML = twemoji.convert.fromCodePoint('1F602'); <script src="//twemoji.maxcdn.com/2/twemoji.min.js?11.0"></script>
<p class="output"></p>
https://stackoverflow.com/questions/51920863
复制相似问题