사용하던 :
var item = layer.get('.rect1'+rect_counter); //dont user "+rec_counter" as this is what binds it to the LAST element
item.on('click', function(){
item.setFill('RED');
});
더 기본적인 해결 방법을 시도해보십시오 -------- 이것은 나를 위해 잘 작동 ---- -------
var itemsList = layer.getChildren(); //gets all shapes in this layer
for(var i=0; i<itemsList.length; i++){
if(itemsList.getName == 'rect1'){ //since you named your rectangles 'rect1' check name
itemsList[i].on('click', function(){
item.setFill('RED');
});
}
};
하거나 바로 사용해보십시오 :
var item = layer.get('.rect'); //all rectangles, without number
item.on('click', function(e){ // I think you need an 'e' here
item.setFill('RED');
});
// I doubt this will work as ALL your rectangles need to have the same name if you want to .get() them all
kinetic.js 및 kode.js에 대한 참조가 없으므로 jsfiddle이 작동하지 않습니다. – SoluableNonagon