<style>
li {
width: 100px;
height: 100px;
background: url(./img/1.jpg) no-repeat;
float: left;
list-style: none;
margin-left: 50px;
}
li.on {
background: url(./img/2.jpg) no-repeat;
}
</style>
<body>
<div>
<li></li>
<li></li>
<li></li>
</div>
<script>
var img = document.querySelectorAll("li");
for (let i = 0; i < img.length; i++) {
img[i].onclick = function(){
for (let j = 0; j < img.length; j++) {
// img[j].className = "";
img[j].classList.remove("on")
}
// this.className = "on"
this.classList.add("on")
}
}
</script>
</body>