简体   繁体   English

svg多边形点-Javascript-不起作用

[英]svg Polygon Points - Javascript - Not Working

How can I control the points of a svg polygon via JavaScript? 如何通过JavaScript控制svg polygon的点? Tried solving it this way, but it does not work. 试图以这种方式解决它,但是它不起作用。

 function points() { document.getElementById("polygon").points = "0,100 0,0 100,100"; } 
 <svg width="100" height="100"> <polygon id="polygon" points="0,0 100,0 100,100" style="fill:#000;"> </svg> <input type="button" onClick="points" value="Change Polygon Points"> 

I've changed the output polygon so that it looks different to the starting polygon, otherwise it looks like the code doesn't do anything. 我已经更改了输出多边形,以使其看起来与起始多边形不同,否则看起来代码没有执行任何操作。

 function points() { document.getElementById("polygon").setAttribute("points", "100,0 50,0 100,100"); } 
 <svg width="100" height="100"> <polygon id="polygon" points="0,0 100,0 100,100" style="fill:#000;"> </svg> <input type="button" onClick="points()" value="Change Polygon Points"> 

document.getElementById('polygon1').setAttribute('points', '100, 0 50, 0 100, 100');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM