P粉1116277872023-08-19 00:43:36
To change the onclick event of an image using JavaScript, you need to have an image with an id:
<p> <img alt="" src="http://www.userinterfaceicons.com/80x80/minimize.png" style="height: 85px; width: 198px" id="imgClickAndChange" onclick="changeImage()"/> </p>
Then, when the image is clicked, you can call the JavaScript function:
function changeImage() { if (document.getElementById("imgClickAndChange").src == "http://www.userinterfaceicons.com/80x80/minimize.png"){ document.getElementById("imgClickAndChange").src = "http://www.userinterfaceicons.com/80x80/maximize.png"; } else { document.getElementById("imgClickAndChange").src = "http://www.userinterfaceicons.com/80x80/minimize.png"; } }
This code will set the image to maximize.png when the current img.src is set to minimize.png and vice versa. For more details, please visit: Changing the onclick event link of an image using JavaScript