abstract:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">&
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>js控制div</title>
<style>
#box{height: 100px;width: 100px;background-color: aquamarine;
margin: 30px 50px; }
</style>
</head>
<body>
<div id='box'></div>
<input type="button" value="变高" onclick="hight()">
<input type="button" value="变宽" onclick="wide()">
<input type="button" value="变色" onclick="color()">
<input type="button" value="重置" onclick="reset()">
<input type="button" value="隐藏" onclick="hide()">
<input type="button" value="显示" onclick="display()">
<input type="button" value="变圆" onclick="circle()">
<script>
var box;
window.onload=function(){
box=document.getElementById('box');
}
function hight(){
box.style.height="400px";//改变高度
}
function wide(){
box.style.width='400px';//改变宽度
}
function color(){
box.style.backgroundColor="red";//改变背景色
}
function reset(){
box.style.height="100px";//重置样式
box.style.width="100px";
box.style.backgroundColor="aquamarine";
}
function hide(){
box.style.display="none";//隐藏样式
}
function display(){
box.style.display="block";//显示样式
}
function circle(){
box.style.borderRadius="50%";//改变圆形
}
</script>
</body>
</html>
Correcting teacher:韦小宝Correction time:2019-02-21 13:59:37
Teacher's summary:通过js来动态的修改div的样式还可以做成动画的效果 从而让页面更有活力