点击张图片A,另一张图片B显示(这时A图片隐藏),
再次点击B图片,A图片显示(这时B图片隐藏)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js实现点击图片切换为另一图片,再次点击恢复到原图片</title>
</head>
<body>
<div id="button">
<img id="picts" src="./images/bg_yellow.png" alt="">
</div>
<script>
function change_pic(){
var button = document.getElementById("button");
var picts = document.getElementById("picts");
button.onclick = function(){
if(picts.getAttribute("src",2) == "./images/bg_yellow.png"){
picts.setAttribute("src","./images/bg_card.png");
}else{
picts.setAttribute("src","./images/bg_yellow.png");
};
}
}
change_pic();
</script>
</body>
</html>