2013-08-24 17 views
1

我试图切换出“d”值并将其替换为动态生成的数字,但我不断收到“意外数字”作为我的输出。以下是我目前拥有的内容:使用javascript在svg路径中切换“d”值?

<path id="pathA" d="M 0 0 l 0 255" stroke="none" stroke-width="0" fill="none"/> 

<script> 
var sink = document.getElementById("pathA"); 
sink.setAttribute("d", M 0 0 l 0 (round*25.5)); 
</script> 
+2

您是否尝试将属性设置为字符串,即'sink.setAttribute(“d”,“M 0 0 l 0”+(round * 25.5));'' –

回答

1

您提交的脚本有两个问题。

首先,你传递给setAttribute的第二个参数是不正确的。请尝试:

sink.setAttribute(“d”,“M 0 0 1 0”+(round * 25.5));

其次,您在任何时候都不提供round的值。