为什么setAttribute在Javascript和SVG中不起作用?

为什么setAttribute在Javascript和SVG中不起作用?,javascript,svg,transform,Javascript,Svg,Transform,我是SVG和Javascript的初学者,如果有人能帮助我,我会很高兴。有人知道为什么要使用SVG和Javascript中的代码吗 <g id="package1"> <rect style="opacity:1;fill:#00b609;fill-opacity:1;stroke:#ffffff;stroke-width:0;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-op

我是SVG和Javascript的初学者,如果有人能帮助我,我会很高兴。有人知道为什么要使用SVG和Javascript中的代码吗

<g id="package1">

  <rect style="opacity:1;fill:#00b609;fill-opacity:1;stroke:#ffffff;stroke-width:0;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" id="rect991" width="1.6536481" height="11.641669" x="145.52083" y="28.447916" />

</g>

<script type="text/javascript" id="move">
  var package1 = document.getElementById("package1");

  package1.setAttribute("transform", "translate(210,120) rotate(-10 50 100)");
</script>

var package1=document.getElementById(“package1”);
package1.setAttribute(“变换”、“平移(210120)旋转(-105010)”;
即使矩形应该旋转,它也不会发生任何变化


谢谢

它有作用。您需要将
rect
放入
svg
元素中

setTimeout(()=>{
var package1=document.getElementById(“package1”);
package1.setAttribute(“变换”、“平移(210120)旋转(-105010)”;
}, 2000);
#包1{
边框:1pt纯红;
}


谢谢,现在我知道代码本身正在工作。我确实把rect加上Javascript代码放在了svg元素中,我将尝试找出问题所在。我在脚本部分删除了更多代码,现在它开始工作了!谢谢@太好了。很乐意帮忙。如果你满意,请投票支持答案。