in Raphael JS

倖福魔咒の 提交于 2019-12-22 06:50:04

问题


I need to do something like:

paper.text(Left, Top, " " + this._p.Label + ":");
paper.text(Left, Top, " " + this._p.Label + ":");

But the prepended whitespace won't show or show as   in text.

I've tried:

label.attr({"xml:space": "preserve"});

...with no effect.

Is there anyway to access the SVG node in Raphael JS so I can set

setAttributeNS("http://www.w3.org/XML/1998/namespace","space","preserve");

(or is there any other way to solve this?)


回答1:


Yes, you can definitely apply that namespaced attribute directly to the SVG element managed by Raphael. It's this simple:

paper.canvas.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space","preserve");

Demonstrated to be functional here.




回答2:


Although this seems somewhat [1] solved, I came across this discussion about the same issue, which rather suggests replacing spaces with \u00a0. This can easily be achieved by using the string function .replace(/ /g,'\u00a0').


1 The leading spaces of the text node in the given link does not work for Mac Safari v.6.0.5. I'm not sure how it looks in other browsers and OS'es.

来源:https://stackoverflow.com/questions/12155954/nbsp-in-raphael-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!