我有一个画布,我使用 jCanva (http://calebevans.me/projects/jcanvas/docs.php?p=layers)s 来创建带有事件的圈子。
我希望每个圆圈都有文本(用于鼠标悬停事件)和 id(用于单击事件)。问题是事件是动态的,并且“i”始终是最后一个 i(data.length),因此所有圆圈都获得相同的值......我该如何解决?
for (i = 0; i < data.length; i++) {
var id = data[i][0];
var text = data[i][2];
$("#mapCanvas").drawArc({
layer: true,
fillStyle: "yellow",
strokeStyle: "#000",
strokeWidth: 1,
x: Math.random() * c.clientWidth,
y: Math.random() * c.clientHeight,
radius: 6,
click: function (layer) {
window.open("Edit/" + id);
},
mouseover: function (layer) {
$("canvas")
.addLayer({
method: "drawRect",
name: "BackgroundLabel",
group: "ItemLabel",
fillStyle: "#FFFFD4",
x: layer.x + 10,
y: layer.y - 15,
width: 100,
height: 20
})
.drawLayers();
$("#mapCanvas").drawText({
layer: true,
fillStyle: "white",
strokeWidth: 0,
x: layer.x + 10,
y: layer.y - 10,
font: "14pt Arial, Verdana, sans-serif",
text: text
});
}
});