在 SVG Text 元素中插入 HTML 代码 [英] Insert HTML code inside SVG Text element
本文介绍了在 SVG Text 元素中插入 HTML 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 svg:text 节点,我想在其中添加 HTML 代码.实际上,我的代码是:
I have an svg:text node, and I want to add HTML code inside it. Actually, my code is:
<text x="10" y="54" text-anchor="start" class="barLegend">Hello!</text>
我想这样写:
<text x="10" y="54" text-anchor="start" class="barLegend"><a href='www.gmail.com'>Gmail</a></text>
当然,我希望链接正常工作,但是,它只是显示所有 HTML.
Of course, I want the link working, but, it is just displaying all the HTML.
有什么想法吗?
推荐答案
在这种情况下为什么不使用 SVG 元素?不要忘记 href 必须是 xlink:href .例如
Why not use an SVG <a>
element in this case? Don't forget that the href needs to be xlink:href though. E.g.
<text x="10" y="54" text-anchor="start" class="barLegend"><a xlink:href='http://www.gmail.com'>Gmail</a></text>
仅 SVG 动画元素、描述性元素(
或
)、文本内容子元素(
code> 或
) 或 SVG 元素被允许作为文本元素的子元素.
Only SVG animation elements, descriptive elements (<title>
or <desc>
), text content child elements (<tspan>
or <textPath>
) or the SVG <a>
element are allowed as children of text elements.
这篇关于在 SVG Text 元素中插入 HTML 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文