<!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>
<button>开关</button>
<script>
var btn = document.querySelector('button')
var body = document.body;
var flag = true
btn.onclick = function() {
if (flag) {
body.style.backgroundColor = 'red'
} else {
body.style.backgroundColor = 'yellow'
}
flag = !flag
}
</script>
</body>
</html>
开关灯按钮
最新推荐文章于 2023-02-18 01:43:10 发布