代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>换皮肤</title>
<style>
*{
padding: 0;
margin: 0;
}
#sketch{
background-color: rgba(255, 255, 255, 0.5);
width: 400px;
height: 58px;
margin-left: 47px;
}
ul{
list-style: none;
}
ul li img{
width: 75px;
float: left;
margin-top: 10px;
margin-left: 20px;
cursor: pointer;
}
#bg{
z-index: -1;
position: absolute;
top: 0;
left: 0;
}
</style>
</head>
<body>
<div id="sketch">
<ul>
<li>
<img src="./image/yt01.jpg" alt="">
</li>
<li>
<img src="./image/yt02.jpg" alt="">
</li>
<li>
<img src="./image/yt03.jpg" alt="">
</li>
<li>
<img src="./image/yt04.jpg" alt="">
</li>
</ul>
</div>
<div id="bg">
<img src="./image/yt02.jpg" alt="" id="bgimg">
</div>
<script>
var bgimg = document.getElementById("bgimg");
var sketchs = document.getElementsByTagName("img");
for (var i =0; i < sketchs.length; i++) {
sketchs[i].onclick = function(){
var smallimgsrc = this.getAttribute('src');
bgimg.setAttribute("src",smallimgsrc)
};
}
</script>
</body>
</html>
结果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/18bbd13f3eda9e5d7d2752352011de9a.png)