<!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>自定义方法,实现通过类名获取对象集合</title>
<style>
.one{
width:500px;
height:500px;
background-color: rgb(112, 236, 168);
line-height: 100px;
}
</style>
</head>
<body>
<div class="one">
<div class="one1">111122</div>
<div class="one2 one1">3333444</div>
<div class="one1">5555666。</div>
<div class="three">7777888</div>
<div class="three2">999</div>
</div>
<script>
var ones = document.getElementsByClassName('one1');
console.log(ones);
for(var i = 0; i < ones.length; i++){
ones[i].style.backgroundColor="red";
ones[i].style.color="blue";
}
</script>
</body>
</html>