<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
img{
width: 19px;
}
</style>
</head>
<body>
<p style="font-size: xx-large">切换图片</p>
<button id="liudehua">刘德华</button>
<button id="zhangxueyou">张学友</button>
<img src="屏幕截图(19).png" title="刘德华">
<script>
//get yuansu
var ldh = document.getElementById('liudehua');
var zxy = document.getElementById('zhangxueyou');
var img = document.querySelector('img');
//sign in shijian
zxy.onclick = function () {
img.src = '谭雅.png';
img.title='谭雅';
}
ldh.onclick=function () {
img.src='屏幕截图(19).png';
img.title='红警';
}
</script>
</body>
</html>
js实现点击按钮图片切换的小功能
最新推荐文章于 2023-11-16 18:50:49 发布