前端学习笔记之选座位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>选座位</title>
<style>
ul {
display: flex;
list-style: none;
}
ul li {
display: block;
width: 41px;
height: 35px;
background: url("../DOM/img/seat.jpg");
background-position: 50px 0;
}
.change {
background: url("../DOM/img/seat.jpg");
background-position: 0 0;
}
</style>
</head>
<body>
<ul>
<li class="change"></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<script>
let ul = document.querySelector("ul");
let list = ul.children;
for (let item of list) {
item.onclick = function () {
change="";
item.className == "change" ? item.className = "" : item.className = "change";
}
}
</script>
</body>
</html>