简体   繁体   English

Javascript:在svg中使用字体图标。 <i>How do I use “\\u”?\u003c/i> 如何使用“ \\ u”?

[英]Javascript: Using font icons in svg's. How do I use “\u”?

I am using font icons generated by icomoon.com and displaying them as svg text using Raphael . 我正在使用icomoon.com生成的字体图标 ,并使用Raphael将它们显示为svg文本

Basically, I have icons like these: 基本上,我有这样的图标:

&#xe005;
&#xf331;
&#xe0c1;
&#xf003;
&#x25;

I have been inserting them into my code like so: 我一直将它们插入到我的代码中,如下所示:

paper.text(x, y, iconString).attr({
   'text-anchor': 'end', 
   'font-family':'myFont', 
   'font-size':12})

BUT, in order for me to get this to work, I've had to use the Javascript way to show icons, but I don't really know enough about it to know what I'm doing wrong. 但是,为了使它起作用,我不得不使用Javascript方法来显示图标,但是我对此并不十分了解,无法知道自己在做什么。 For example: 例如:

iconString = "\ue005"; //This is for icon "&#xe005;". Works!
iconString = "\uf331"; //This is for icon "&#xf331;". Works!
iconString = "\ue0c1"; //This is for icon "&#xe0c1;". Works!
iconString = "\uf003"; //This is for icon "&#xf003;". Works!
iconString = "\u25"; //This is for icon "&#x25;". DOES NOT WORK!

So I've just been replacing "&#x" with "\\u\u0026quot; and it has been working... but not when it is short. 因此,我刚刚用“ \\ u”替换了“&#x”,并且它一直在起作用...但是当它很短时却没有。 :/ How do I do this? :/ 我该怎么做呢?

I've also used the whole string (like "&#xf003;" , but that has only been working in text and not svg for me.) 我还使用了整个字符串(例如"&#xf003;" ,但这仅适用于文本而不是svg。)

Any ideas? 有任何想法吗? Thanks! 谢谢!

\\u\u003c/code> requires four digits. \\u\u003c/code>需要四位数。

iconString = "\u0025";

Alternatively, two-digit numbers can also be done like so: 或者,也可以像这样完成两位数的数字:

iconString = "\x25";

Alternatively alternatively, you can just use the plain character: 或者,您可以只使用普通字符:

iconString = "%";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM