Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 动态更新SVG文本节点_Javascript_Svg - Fatal编程技术网

Javascript 动态更新SVG文本节点

Javascript 动态更新SVG文本节点,javascript,svg,Javascript,Svg,我想更新图片中的一些SVG文本标签。我首先调用一个组,然后减去它的子节点,得到纯文本节点,从而得到所有节点: let textLabels = document.getElementById('texts').children 因此,我得到了一个包含所有文本节点的HTMLCollection。然后,我想在这些节点上更新/设置新文本,因此我正在尝试: Array.from(textLabels).forEach(function (i) { i.textContent(...) } ,我

我想更新图片中的一些SVG文本标签。我首先调用一个组,然后减去它的子节点,得到纯文本节点,从而得到所有节点:

let textLabels = document.getElementById('texts').children
因此,我得到了一个包含所有文本节点的HTMLCollection。然后,我想在这些节点上更新/设置新文本,因此我正在尝试:

Array.from(textLabels).forEach(function (i) {
   i.textContent(...)
}
,我得到:TypeError:I.textContent不是一个函数

textLabels数组如下所示:

0: text#label_0
1: text#label_1
2: text#label_2
我应该如何设置这些文本?

文本内容不是一个函数。可以直接为其指定值:

Array.from(textLabels).forEach(function (i) {
   i.textContent = 'some text'
}

更多文档请点击此处:

@Mark\u M:请将其作为答案发布,它有助于:-