我有一个必须输入坐标位置的文本框。然后通过单击Set,将文本(坐标)分配给变量c。单击Draw会绘制一条到定义坐标的路径。
我想要做的是每次单击Draw时更新现有路径。但它所做的只是在我单击Draw时不断创建新路径。我哪里错了?
这是小提琴
<html>
<head>
<script src="raphael.js"></script>
<script>
var c, previous1, linepath;
var l = 5;
var x = 1;
window.onload = function(){
set = function(){
c = document.getElementById("b1").value;//get the co-ords
circ();//draw circle at the select co-ord
}
var paper = Raphael(0,80,600,600);
draw = function(){
if (x==1){
previous1 = "M100,100 L";
x++;
}else{
previous1 = window.linepath + " ";
}
var new1 = previous1 + window.c;
linepath = new1;
var line = paper.path(linepath);
var path = paper.text(10,l,linepath);
path.attr({"text-anchor":"start","font-size":"12"});
l = l+10;
};
function circ(){
var posX = c.substring(0,3);
var posY = c.substring(4,7);
var circl = paper.circle(posX,posY,5).attr({fill:'red',stroke:'none'});
};
}
</script>
</head>
<body>
Enter co-ords > Click Set > Click Draw
<br>
<input type="text" id="b1" value="100,400">
<button type="button" onclick="set()">Set</button>
<button type="button" onclick="draw()">Draw</button>
</body>
</html>