<!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>
</head>
<body>
<input type="button" value="开关灯">
</body>
<script>
var bo = document.body;
var ipt = document.querySelector("input");
var flag=1;
ipt.onclick = function(){
if(flag===1){
flag = 0;
bo.style.backgroundColor='black';
}else{
bo.style.backgroundColor='#fff';
flag = 1;
}
}
</script>
</html>
JS开关灯「作业」
猜你喜欢
转载自blog.csdn.net/weixin_60789461/article/details/123610806
周排行