美好的一天,追加路径的孩子使用JavaScript
我有创造的路径和使用“的appendChild”的SVG元素中显示它令人难以置信的困难。
我不得不错过一些非常简单的事情,因为我倾注了W3C的规范,w3schools.com,在这里的各种职位,并尝试以各种方式忍者谷歌。
我在FireFox和Chrome中测试。
我有这样一个简单的SVG文件:
<svg xmlns:svg ... id="fullPageID">
<image id="timer1" x="100" y="100" width="100px" height="100px" xlink:href="../component/timer/timer1.svg" />
<image id="battery1" x="200" y="200" width="100px" height="100px" xlink:href="../component/battery/30x20_ochre.svg" />
<script xlink:href="pathMaker.js" type="text/javascript" id="pathMaker" />
</svg>
我试图使用该脚本的样子:
newpath = document.createElementNS("SVG","path");
newpath.setAttribute("id", "pathIdD");
newpath.setAttribute("d", "M 1,97.857143 C 19.285714,96.428571 24.016862,131.64801 90.714286,132.85714 140.78762,133.7649 202.79376,66.16041 202.79376,66.16041");
newpath.setAttribute("stroke", "black");
newpath.setAttribute("stroke-width", 3);
newpath.setAttribute("opacity", 1);
newpath.setAttribute("fill", "none");
document.getElementById("fullPageID").appendChild(newpath);
我只想做一些简单的工作。我错误地认为我不需要像Library to generate SVG Path with Javascript?那样复杂的解决方案?
谢谢。
你可能会喜欢 '接受' 的答案之一。 – phils