<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> .cls { background-color: black; } </style> </head> <body> <input type="button" value="开/关灯" id="bt"/> <script src="common.js"></script> <script> my$("bt").onclick = function () { //获取body标签 document.body.className = document.body.className != "cls" ? "cls" : ""; }; </script> </body> </html>
原文地址:https://www.cnblogs.com/cuilichao/p/9344638.html
时间: 2024-10-11 12:33:56