zjm*_*126 23 javascript svg raphael
我正在使用raphaeljs,我想在svg中显示html(不仅是文本),
所以我使用这段代码:
var r = Raphael("holder", 200, 300);
var t = r.text(10, 10, "ssdwqdwq");
t.node.innerHTML='dddd'
Run Code Online (Sandbox Code Playgroud)
但我不能改变svg的内容,所以我在firebug中安装它,
console.log(t.node)
Run Code Online (Sandbox Code Playgroud)
它显示了这个:
<text x="10" y="13.5" text-anchor="middle" style="font: 10px "Arial";" font="10px "Arial"" stroke="none" fill="#000000">
Run Code Online (Sandbox Code Playgroud)
所以如何在svg上使用javscript更改文本
谢谢
con*_*att 10
我能够通过设置元素的 textContent 属性来实现这一点<text>。如果您知道元素的 ID,这将变得容易得多。
document.getElementById("id-of-text-el").textContent = "My Value";
Run Code Online (Sandbox Code Playgroud)
小智 5
如果 svg 文本的代码是这样的:
<text id="id-of-the-text"> old value</text>
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 JQuery,请尝试以下操作:
$("#id-of-the-text").text("new-value");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
46878 次 |
| 最近记录: |