div css样式控制案例

原创2018-12-24 14:43:48202
摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>div -css样式控制案例</title> <style> #box{width:100px; height: 100px;


<!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>

QQ截图20181224144321.png

批改老师:天蓬老师批改时间:2018-12-24 15:24:05
老师总结:这个案例很有创意, 相信写完之后, 对基本的样式控制基本上掌握了

发布手记

热门词条