<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
.div1{width: 50px; height: 50px; background: yellow;}
.div2{width: 50px; height: 50px; background: red; }
</style>
<script>
window.onload=function(){
/*只能获取元素 的第一个*/
var odiv=document.querySelector('.div1');
var oall=document.querySelectorAll('div');
odiv.style.background="red";
oall[1].style.height='1000px';
var odiv3=document.getElementById('div3');
/*类似于数组的对象*/
alert(odiv3.classList);
odiv3.classList.add('box7');
odiv3.classList.remove('box3');
odiv3.classList.toggle('box4');
}
</script>
</head>
<body>
<div class="div1"></div>
<div class="div2"></div>
<div id="div3" class="div3 div4 div5"></div>
</body>
</html>
html5 选择元素
最新推荐文章于 2021-06-03 05:12:11 发布