【发布时间】:2016-02-09 09:31:46
【问题描述】:
我有包含代码的外部 SVG 文件
<g
inkscape:groupmode="layer"
id="layer9"
inkscape:label="score"
style="display:inline">
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:22.5px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
x="100.3568906"
y="20.353357"
id="text5833"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan5834"
x="300.3568906"
y="20.353357">Score</tspan></text>
</g>
我需要动态更改 JS 文件中的文本分数,我已经尝试过但无法动态更改文本。 我尝试的是:-
var list = layerNamed('score').getElementsByTagName("g");
var textNode = document.createTextNode("Score:-1");
list.appendChild(textNode);
【问题讨论】:
-
不相关,但如果您要广泛使用
svg,请尝试 d3.js。 -
@Robert Longson 我也尝试使用文本但没有用..
标签: javascript css svg