简体   繁体   English

svg文本元素是否具有内容属性?

[英]Do svg text elements have content attributes?

Do svg text elements have content attributes? svg文本元素是否具有内容属性?

I believe this can be achieved with javascript: 我相信可以使用javascript来实现:

document.getElementById("test").textContent("Some meaningful verbage");

Can this be achieved without javascript? 没有javascript可以实现吗? Ex.gr.: Ex.gr:

<text id='test' content="Some meaningful verbage"></text>

While you cannot put the text of a svg text element in an attribute you can append a text element (with text) with javascript like this. 虽然您无法将svg文本元素的文本放在属性中,但是可以使用javascript附加文本元素(带有文本)。

 function getNode(n, v) { n = document.createElementNS("http://www.w3.org/2000/svg", n); for (var p in v) n.setAttributeNS(null, p.replace(/[AZ]/g, function(m, p, o, s) { return "-" + m.toLowerCase(); }), v[p]); return n } var svg = getNode("svg"); document.body.appendChild(svg); var text = getNode('text', {x:"15", y:"15", fill: "black"}); text.append("some meaningful text"); svg.appendChild(text); 

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

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