使用js实现选座

    技术2023-11-06  102

    <!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>
    Processed: 0.028, SQL: 9