什么是字符代码♥和如何使用它

what is the character code for ♥ and how to use it?

本文关键字:何使用 字符 代码 什么      更新时间:2023-09-26

我正在创建一个emoticon js脚本,我似乎无法获得工作的字符代码,我尝试过♥作为字符代码,但不工作任何帮助将是有帮助的

my script

jQuery.fn.emotion_func = function(icon_folder) {
var emotion_locate =  "emotions";
var key_stroke = { ....
         "heart": Array("♥")//it dosent work 
                   ....
             };
function emotion_func(html){
for(var emotion in key_stroke){
    for(var i = 0; i < key_stroke[emotion].length; i++){
        var key = new RegExp(key_stroke[emotion][i],"g");//replace all occurenced
        html = html.replace(key,"<span style='"background-image:url("+emotion_locate+"/"+emotion+".png); '" title="+emotion+" /></span>");
                }
            }
            return html;
        }
        return this.each(function(){
            $(this).html(emotion_func($(this).html()));
        });
    };

任何帮助都将是感激的

还请注意,我使用html 5

对不起,只有@hwnd的回答对我有用

您需要在数组中实际使用Unicode转义序列'u2665进行替换。

var key_stroke = { 'heart': Array(''u2665') };

您要查找的术语是"entity "。HTML中只有几个命名实体,但您可以通过其unicode ID指定任何字符:

&#x2665;将显示为:♥

try

&hearts;
<<p> 小提琴演示/strong>

HTML字符码

http://text-symbols.com/html/entities-and-descriptions/

&#x2665;

演示小提琴

注意:不要忘记指定

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

meta标签too

<meta http-equiv="Content-Type">

黑心字符的unicode代码为2665。在HTML中,unicode符号可以以前缀代码后缀的格式输出,其中前缀总是&#x后缀总是;。您想要输出的字符的代码是2665,所以可以这样做:

<p>character - &#x2665;</p>

输出为:

character - ♥

由于要将字符添加到JavaScript数组对象中(作为文字),因此需要在JavaScript中使用unicode字符表示(如@hwnd所建议的),在unicode字符之前使用'u(后跟字符代码):

var a = Array(''u2665');
$('#panel').text(a[0]);

对包含所有字符代码的unicode表的引用:unicode字符表

心形标志的另一个HTML代码:♥

&#9829;

看到它在这个JSFIDDLE演示中工作

红心符号十六进制代码

如果你想使用红心变体,你必须使用两个unicode:
U+2764 -代表重黑心
U+FE0F -是变异选择器

插入❤️符号在html类型它是十六进制<p>&#x2764;&#xFE0F;</p>

你可以在这里看到HTML和JavaScript中不同的特殊符号和数学符号