02 显示和隐藏图片
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<button id="btn">隐藏</button>
<br>
<img src="./image/1.jpg" id="cat" width="400px" height="400px">
<script type="text/javascript">
//1.获取事件源
var obtn = document.getElementsByTagName('button')[0];
var catImg = document.getElementsByTagName('img')[0];
// var isShow = true;
//绑定事件
obtn.onclick = function(){
//3.设置驱动程序
if (obtn.innerHTML === '隐藏') {
catImg.style.display = 'none';
obtn.innerHTML = '显示';
// isShow = false;
}else{
catImg.style.display = 'block';
obtn.innerHTML = '隐藏';
// isShow = true;
}
}
</script>
</body>
</html>