我添加了 10 个可拖动的矩形,我希望能够在它们被一个一个单击时将它们删除。现在它只删除第一个,然后不再删除。是否可以向矩形 ID 添加点击事件?
var stage = new Kinetic.Stage({
container: 'container',
width: 578,
height: 400
});
var layer = new Kinetic.Layer();
for (var i = 0; i< 10; i++) {
var rect = new Kinetic.Rect({
x: 239 + (i *3),
y: 75 + (i * 3),
width: 100,
height: 50,
fill: 'blue',
stroke: 'black',
strokeWidth: 4,
draggable: true,
id: i
});
rect.on('click', function() {
rect.hide();
});
// add the shape to the layer
layer.add(rect);
// add the layer to the stage
stage.add(layer);
}