如何使用kineticjs更改图像的id

How to change id of image using kineticjs

本文关键字:图像 id 何使用 kineticjs      更新时间:2023-09-26

首先我用id:image1创建一个图像,然后我想将id image1更改为image2,并使用id:image1创建新图像...我试过了,但它不起作用。谁能帮我?

            var image = new Kinetic.Image({
                    name: data,
                    id: "image1",
                    x: stage.getWidth()*0.5-20,
                    y: stage.getHeight()*0.5-125,
                    width:20,
                    height:250,
                    image: theImage,
                    draggable: false
                });
         image.setId("image2");
         var image = new Kinetic.Image({
                        name: data,
                        id: "image1",
                        x: stage.getWidth()*0.5-200,
                        y: stage.getHeight()*0.5-125,
                        width:20,
                        height:250,
                        image: theImage,
                        draggable: false
             });
      var kk=stage.find("#image1")[0];
      kk.setId("image2");