JavaScript控制DIV
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>控制DIV</title>
<style>
/*设定DIV的初始值*/
#box{
width: 100px;
height: 100px;
background: red;
margin: 20px 80px;
}
</style>
</head>
<body>
<script>
var box
window.onload=function () {
box=document.getElementById('box')
}
function ChangeHeight() {
box.style.height="400px"
}
function ChangeWidth() {
box.style.width="400px"
}
function ChangeColor() {
box.style.background="pink"
}
function ReP() {
box.style.height="100px"
box.style.width="100px"
box.style.background="red"
}
function YC() {
box.style.display="none"
}
function SPlay() {
box.style.display="block"
}
</script>
<div id="box"></div>
<input type="button" value="变高" onclick="ChangeHeight()">
<input type="button" value="变宽" onclick="ChangeWidth()">
<input type="button" value="变色" onclick="ChangeColor()">
<input type="button" value="重置" onclick="ReP()">
<input type="button" value="隐藏" onclick="YC()">
<input type="button" value="显示" onclick="SPlay()">
</body>
</html>