<body>
<button>关灯</button>
<script>
var btn = document.querySelector('button');
var flag = 0;
btn.onclick = function () {
if (flag == 0) {
btn.innerHTML = '开灯';
document.body.style.backgroundColor = '#000';
flag = 1;
} else {
btn.innerHTML = '关灯';
document.body.style.backgroundColor = '#fff';
flag = 0;
}
}
</script>
</body>
开关灯案例
最新推荐文章于 2023-10-15 23:00:40 发布