jquery .text()和unicode [英] jquery .text() and unicode
问题描述
我想在我的HTML中显示打开锁定字符链接文本。
I'd like to display the "Open Lock" character in my HTML link text.
如果直接使用< a id =myId>&#x1f512;<<<<<< ; / a>
,但我发现无法用jQuery .text()
函数进行更改,如下所示:
If I do it directly it shows up correctly with <a id="myId">🔒</a>
, but I found no way to change it dinamically with the jQuery .text()
function, like in:
$("#myID").text(openLockText);
我应该在openLockText中放置什么?
What should I put in openLockText?
推荐答案
Javascript在内部只支持UTF-16。
Javascript internally only supports UTF-16.
因为这是一个扩展的32位UTF字符(不在Basic多语言平面),您需要插入UTF-16代理对,它可以在链接到的相同页面上提供:
Because this is an extended 32-bit UTF character (not in the "Basic Multilingual Plane") you need to insert the "UTF-16 surrogate pair", which is helpfully provided on the same page that you linked to:
0xD83D 0xDD13
i.e.
$('#myId').text('\ud83d\udd13');
更多详情可在 RFC 4627 ,严格来说这是JSON的格式。
More details can be found in RFC 4627, which is strictly speaking the format for JSON.
这篇关于jquery .text()和unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!