点击按钮切换图片
点击按钮在两张图片之间切换.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="button" value="点击" id="btn"><br>
<img src="images/a.jpg" id="pic">
<script>
//获取元素
var btn = document.getElementById("btn");
var pic = document.getElementById("pic");
var num =1;
btn.onclick = function(){
if(num == 1){
pic.src = "images/b.jpg";
num = 0;
}else {
pic.src = "images/a.jpg";
num = 1;
}
};
</script>
</body>
</html>