<!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>
<style>
img{
width: 100px;
}
</style>
</head>
<body>
<img src="./1.jpg" alt="">
<img src="./2.jpg" alt="">
<img src="./3.webp" alt="">
<img src="./4.jpg" alt="">
</body>
<script>
var imgs=document.getElementsByTagName("img")
for( var i=0;i<imgs.length;i++){
imgs[i].onclick=function(){
var num=this.src
var bodyElement=document.body
bodyElement.style.backgroundImage="url("+num+")"
}
}
</script>
</html>
标签:换肤,img,getElementsByTagName,javascript,imgs,var,document,百度
From: https://blog.csdn.net/2401_83905000/article/details/142651100