div css样式控制案例
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>div -css样式控制案例</title>
<style>
#box{width:100px; height: 100px; background: pink;display="none"}
</style>
</head>
<body>
<div id="box">
</div>
<input type="button" value="变红" onclick="bred(this)">
<input type="button" value="变大" onclick="bda(this)">
<input type="button" value="变圆" onclick="byuan(this)">
<input type="button" value="还原" onclick="bhuan(this)">
<input type="button" value="隐藏" onclick="byin(this)">
<input type="button" value="显示" onclick="bxian(this)">
<script >
var box
window.onload=function() {
box=document.getElementById('box')//全局声明
}
function bred() {
box.style.background="red"//变红
}
function bda() {
box.style.width="120px"
box.style.height="120px"//变大
}
function byuan() {
box.style.borderRadius="60px"//变圆
}
function bhuan() {
box.style.borderRadius="0px"//还原
box.style.width="100px"//还原
box.style.height="100px"//还原
box.style.background="pink"//还原
}
function byin() {
box.style.display="none"//隐藏
}
function bxian() {
box.style.display="block"//显示
}
</script>
</body>
</html>
![1545633817328957.png QQ截图20181224144321.png](http://img.php.cn//upload/image/142/894/527/1545633817328957.png)