简体   繁体   中英

How can i change the src of an image when i click on another image

I have two images. One of the images is inside a forEach and one is not. I want it so when i click on image 'item' that the source of the image 'this._sel' is changed.

At the moment my page loads fine and i have both images. When i click on image 'item' the source of 'this._sel' does change, however, the image remains the same.

The console shows that the source changes but the page does'nt alter the image it remains on the same image. Any ideas how i can fix this?

Thank you :)

this._sel = new m.Image({
    width: "30px",
    press: function() {
       pop.openBy(this);
    }
});

lar.forEach(function(v){

    var item = new m.Image({
    width:"50px",
    src: "hello.png",
    press: function(event) {
        var Map = this._sel;
            Map.setSrc(item.getSrc());
    }.bind(this)
    });
}

This is strange. The image should automatically render when you change its src attribute. Does this happen in every browser? I was not able to reproduce your issue.

You can perhaps try to remove the image and replace it with a new image that has the new src attribute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM