<!DOCTYPE html>
<html>
<head>
<title>get Elements By Tag Name</title>
</head>
<script type="text/javascript">
window.onload=function()
{
var aDiv=document.getElementsByTagName('div');
for (var i = 0; i<aDiv.length; i++)
{
aDiv[i].style.background='red';
};
};
</script>
<style type="text/css">
div{
width: 100px;
height:100px;
border: 1px solid red;
margin: 50px;
float: left;
}
</style>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
</html>
网友评论