简体   繁体   English

svg dom使用变量定义对象属性

[英]svg dom use variables to define object attributes

can you help me? 你能帮助我吗? I want to use javascript in order to alter the form of a svg polygon using given variables. 我想使用javascript,以便使用给定变量来更改svg多边形的形式。 I tried this: 我尝试了这个:

var example = 200;
document.getElementById('myPolygon').setAttribute('points','50,50 50,100 example,100');

It does not work. 这是行不通的。 The double quotation mark doesn't work, either. 双引号也不起作用。 However, I need the variable because it changes over time. 但是,我需要变量,因为它会随时间变化。 What is the right syntax in this case? 在这种情况下正确的语法是什么?

I have looked for such a question, but didn't find it. 我一直在寻找这样的问题,但没有找到。 If there is already a solution for my question provided on this forum, please kindly let me know the link to it. 如果此论坛上已经提供我的问题的解决方案,请告诉我它的链接。 Thank you! 谢谢!

try this.you should append the value of variable example between the string. 试试这个。您应该在字符串之间附加变量example的值。 if you use '50,50 50,100 example,100' ,example is considered as a part of string. 如果您使用'50,50 50,100 example,100' ,则example被视为字符串的一部分。 '50,50 50,100 '+example+',100' here you are adding value of variable example to string. '50,50 50,100 '+example+',100'在这里,您要将变量example值添加到字符串。

document.getElementById('myPolygon').setAttribute('points','50,50 50,100 '+example+',100');

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

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