jquery .text() and unicode

后端 未结 4 942
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 15:03

I\'d like to display the \"Open Lock\" character in my HTML link text.

If I do it directly it shows up correctly with 🔒<

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-01 15:37

    editedIf it were a Unicode code point that could be represented in a single UTF-16 character, then ou could use JavaScript escape sequences in such situations:

    $('#foo').text('\uXXXX');
    

    However, because your character requires more bits, that doesn't work. It would probably be possible to construct the byte sequence that'd allow the character to be represented as UTF-16, but it'd be a pain. I'd go with .html().

    Note that not all fonts provide glyphs for "exotic" code points like that, and in my experience those that do provide incredibly ugly ones.

提交回复
热议问题