Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
访问器属性就是将原本的属性伪装成方法,这样就可以直接区访问不用一级一级跳着选择
1.document.querySelectorAll 获取所有元素
2.document.querySelector获取第一个元素
<!DOCTYPE html>
<html lang="zh-CN">
<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 onclick="blue()">蓝色</button>
<button onclick="red()">第一个红色</button>
<div class="box">box1</div>
<div class="box">box2</div>
<div class="box">box3</div>
<div class="box">box4</div>
<div class="box">box5</div>
<div class="box">box6</div>
<script>
document.querySelectorAll(".box");
const box1 = document.querySelectorAll(".box");
function blue() {
for (let i = 0; i < box1.length; i++) {
box1[i].style.color = "blue";
}
}
let box2 = document.querySelector(".box");
function red() {
box2.style.color = "red";
}
</script>
</body>
</html>