JavaScript - SVG Text 返回'undefinded'



我试图在SVG中创建一个文本节点并更改它的颜色然而,它不断返回"未定义">

const shp = document.createElementNS("http://www.w3.org/200/svg","text");
const textNode = document.createTextNode(this.data["ctx"]);
const shp.appendChild(textNode);
shp.style.fill = 'red';

这是我的结果:

Uncaught TypeError: Cannot set property 'fill' of undefined

我编码错了吗?

这个问题与您的命名空间有关,您有200而不是2000,就像这样:xmlns="http://www.w3.org/2000/svg"。你可以在这里看到一把正在工作的小提琴。

PS。undefined在您的问题标题中拼写错误

最新更新