慕少1832090
2018-07-28 14:35
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
.divl{
width: 200px;
height: 200px;
}
</style>
</head>
<body>
<div class="divl"></div>
<div class="divl"></div>
<div class="divl"></div>
<script type="text/javascript">
for(var i=0;i<document.getElementsByClassName('divl').length;i++)
{
document.getElementsByClassName('divl')[i].backgroundColor='red';
}
</script>
</body>
</html>
document.getElementsByClassName('divl')[i].style.backgroundColor='red';
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题