【问题标题】:How to use svg text tag in javascript如何在 javascript 中使用 svg 文本标签
【发布时间】:2012-08-06 11:06:55
【问题描述】:

我可以在 javascript 中使用 SVG 文本标签。但它不起作用。这是我的 Javascript 代码。

O=evt.target;
Doc=O.ownerDocument;    
L = Doc.createElementNS(xmlns, "text");
L.setAttribute("x", 10);
L.setAttribute("y", 10);
L.node.textContent("abcdef");
L.setAttribute("fill", "red");
O.appendChild(L);

以 SVG 文本标签为例:

<text x="10" y="10" fill="red">abcdef</text>

我的 javascript 代码中有什么类型的错误。 问候,维吉

【问题讨论】:

标签: javascript jquery css svg


【解决方案1】:

这很好用

​<svg>
    <text x="10" y="10" fill="red">abcdef</text>
</svg>

here是一个工作的javavascript example。我没有您的完整代码,因此很难确定您的确切问题。

编辑: 我想我找到了。 L.node.textContent("abcdef"); 应该是 L.textContent = "abcdef"; new fiddle

更多示例here

【讨论】:

  • @Viji 没问题!您介意将其标记为答案吗?谢谢!
猜你喜欢
  • 2011-05-15
  • 2021-12-07
  • 2013-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-10
  • 2016-11-16
相关资源
最近更新 更多