Changing Images src with Event “onclick”

前端 未结 5 1471
谎友^
谎友^ 2021-01-13 18:54








        
5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-13 19:44

    image.src returns the physical path of image. So you can use indexOf to match image name. Following code snippet may help you.

    function changeColor(image) {
        if (image.src.indexOf("circleRed.png")>-1) {
            image.src = "circleBlue.png"; 
        } else {
            image.src = "circleRed.png";
        }
    }

提交回复
热议问题