<!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>
<style>
.main {
margin: 100px auto;
width: 500px;
height: 500px;
background-color: rgb(158, 164, 162);
overflow: hidden;
}
.father {
margin: 30px auto;
width: 200px;
height: 200px;
margin-bottom: 20px;
background-color: blueviolet;
}
.father div {
width: 30px;
height: 30px;
margin-bottom: 5px;
background-color: yellow;
}
.mother {
margin: auto;
width: 200px;
height: 200px;
background-color: blue;
}
.mother div {
width: 30px;
height: 30px;
margin-bottom: 5px;
background-color: yellowgreen;
}
</style>
</head>
<body>
<div class="home">
<div class="main">
<div class="father" id="worker">
<div></div>
<div class="top"></div>
<div class="buttom"></div>
<span>one</span>
<span>two</span>
<span>three</span>
</div>
<div class="mother">
<div></div>
<div></div>
<div></div>
<span>four</span>
<span>five</span>
<span>six</span>
</div>
</div>
<div class="main"></div>
<div class="main">three</div>
<div class="main"></div>
<div class="main"></div>
<div class="main"></div>
<div class="main"></div>
</div>
<script>
var home = document.querySelector('.home');
var main = document.getElementsByClassName('main');
var main_arr = home.querySelectorAll('div');
var one_main = main[0];
var first_main = main_arr[0];
one_main.style.backgroundColor='red'
first_main.style.backgroundColor='red'
</script>
</body>
</html>
这个应该是编辑器的问题,只要代码能执行
取class的name,少个点
我看了下还真是,应该是html相关插件不完善,没有识别导致的