我正在尝试构建一个程序,该程序将在文本框中接受用户输入并显示它。我的问题是,当我在文本框中输入新输入时,帽子输入与第一个文本重叠。我想要的是将原始文本删除并替换为新输入。我正在使用的代码如下。
function eccentricityChanged() {
let svg = document.getElementById('diagram');
let text = document.createElementNS('http://www.w3.org/2000/svg','text');
text.setattribute('x',585);
text.setattribute('y',275);
text.setattribute('fill','red');
svg.appendChild(text);
svg.selectAll('*').remove();
let txt = document.getElementById("eccentricity").value;
parseFloat('text',txt);
text.innerHTML = txt;