![69a428b82113ec28df797abd366d6391.png](https://i-blog.csdnimg.cn/blog_migrate/75ae8f552697681c231fdb6d89d5872a.jpeg)
Ⅰ 开关灯案例
- 点击按钮实现团变色
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>开关灯案例</title>
<style>
#d1 {
height: 200px; width: 200px; border-radius: 50%; }
.box1 {
background-color: red; }
.box2 {
background-color: yellow; }
</style>
</head>
<body>
<div id = 'd1' class="box1 box2"></div>
<button id = 'd2'>点我有你好看</button>
<script>
let idEle = document.getElementById('d2')
let divEle = document.getElementById('d1')
idEle.onclick = function () {
divEle.classList.toggle('box2')
}
</script>
</body>
</html>
![10dfd236103e52dcaea4b7596784b6a8.png](https://i-blog.csdnimg.cn/blog_migrate/181a2e5d678181f7a9a17c72723c2691.jpeg)
Ⅱ input框获取焦点失去焦点案例
- 鼠标不在输入框,默认显示自定义的值
- 鼠标点击输入框后,清空输入框内的值
&