我有多个相同的图像。当我单击其中一个时,需要更换 img。我有 JS 脚本:
var newsrc = "slide_down";
function changeImage() {
if ( newsrc == "slide_down" ) {
document.images["pic"].src = "img/slide_up.png";
document.images["pic"].alt = "slide_up";
newsrc = "slide_up";
}
else {
document.images["pic"].src = "img/arrow.png";
document.images["pic"].alt = "slide_down";
newsrc = "slide_down";
}
}
但是当我按第二个img时,总是第一个被替换。请帮忙。图片的HTML代码是<img src="img/arrow.png" alt="slide_up" class="head" id="pic" onclick="changeImage()">