SVGのテキスト要素の値を読み込んで更新しようとしています。SVGの<text>要素の値を取得して設定する方法
ユーザーが(+)または( - )を押すと、2つの符号の間の値が増分または減分され、ページ上で更新されます。そのためには、私は 'text'要素の現在の値を読んでそれを更新できる必要があります。ここで
はJSFiddle http://jsfiddle.net/hVyTJ/150/とコードです:
<div>
<table>
<tr>
<td>
<svg width="320" height="65">
<text x="213" y="48" style="fill:black;font-size:24;" >+</text>
<text x="284" y="39" style="fill:black;font-size:24;">_</text>
<circle cx="220" cy="40" r="15" stroke="black" stroke-width="0.5" fill="none" />
<circle cx="290" cy="40" r="15" stroke="black" stroke-width="0.5" fill="none" />
<rect onclick="AddQuantity(event, this);" x="200" y="20" width="40" height="40" style="fill-opacity:0.1" />
<rect onclick="AddQuantity(event, this);" x="270" y="20" width="40" height="40" style="fill-opacity:0.1" />
<text x="247" y="45" style="fill:black;font-size:12;">800</text>
</svg>
</td>
</tr>
<tr>
<td>
<svg width="320" height="65">
<text x="213" y="48" style="fill:black;font-size:24;" >+</text>
<text x="284" y="39" style="fill:black;font-size:24;">_</text>
<circle cx="220" cy="40" r="15" stroke="black" stroke-width="0.5" fill="none" />
<circle cx="290" cy="40" r="15" stroke="black" stroke-width="0.5" fill="none" />
<rect onclick="AddQuantity(event, this);" x="200" y="20" width="40" height="40" style="fill-opacity:0.1" />
<rect onclick="AddQuantity(event, this);" x="270" y="20" width="40" height="40" style="fill-opacity:0.1" />
<text x="247" y="45" style="fill:black;font-size:12;">900</text>
</svg>
</td>
</tr>
</table>
</div>
<script>
function AddQuantity(event,x) {
event.stopPropagation();
var y = x.parentNode.lastChild;
alert(y);
// Not Sure how to retrieve the value
var z = x.parentNode.lastChild.nodeValue;
alert(z);
// Not Sure how to set the value
x.parentNode.lastChild.nodeValue = 777;
}
</script>
ヘルプは高く評価されます。
感謝ロバート。これは素晴らしい。これらのすべてのノード/子値にアクセスする方法を説明する簡単なリファレンスを教えてください。 – Anjum
https://developer.mozilla.org –