更改文本svg JavaScript

Change text svg JavaScript

本文关键字:JavaScript svg 文本      更新时间:2023-09-26

如何在JavaScript中用"txtcircle"更改文本分配ID?我的对象如下:

<svg  width="100" height="100" id="svgcircle" > 
                <rect id="circle1" x="5" y="25" width="50" height="50" stroke="#0E0E0E" style="fill:red; stroke-width:1" />
                 <text id =txtcircle x="5" y="35" font-family="Verdana" font-size="11" fill="white" > Rect1 </text>
            </svg> 

我还想通过使用JavaScript编写所需的文本来更改文本(ID = 'Rect1')

您可以执行此

var elem = document.getElementById('txtcercle');
elem['innerText' in elem ? "innerText" : "textContent"] = "some value";