JavaScript控制DIV样式

Original 2019-03-22 09:18:16 205
abstract:<!doctype html><html><head><meta charset="utf-8"><title>javascript</title><style type="text/css">#box{ width:200px; height:200px; backgrou

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>javascript</title>

<style type="text/css">

#box{ width:200px; height:200px; background:#36F; margin:10px;}

</style></head><body>


<div id="box"></div>

<input type="button" value="变高" onclick="aa()">

<input type="button" value="变宽" onclick="bb()">

<input type="button" value="变色" onclick="cc()">

<input type="button" value="重置" onclick="dd()">

<input type="button" value="隐藏" onclick="ee()">

<input type="button" value="显示" onclick="ff()">

<script type="text/javascript">

 var box

 window.onload=function(){box=document.getElementById("box")}

 function aa(){box.style.height="300px"}

 function bb(){box.style.width="300px"}

 function cc(){box.style.background="red"}

 function dd(){

box.style.height="200px"

box.style.width="200px"

box.style.background="#36F"

 

 }

 function ee(){box.style.display="none"}

 function ff(){box.style.display="block"}

</script>


</body>

</html>


Correcting teacher:灭绝师太Correction time:2019-03-22 09:20:04
Teacher's summary:上课的练习比较简单,案例可以自行拓展哦!

Release Notes

Popular Entries