サマリー:<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>changDIV</title> <style type="text/css&quo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>changDIV</title>
<style type="text/css">
#box{width:100px;height:100px;background:red;margin:100px 100px;}
</style>
<script type="text/javascript">
var box
window.onload=function(){
box=document.getElementById('box')
}
function a(){
box.style.height="400px"//變高
}
function b(){
box.style.width="400px"//變寬
}
function c(){
box.style.background="pink"//變色
}
function d(){
box.style.height="100px"//重置
box.style.width="100px"
box.style.background="red"
}
function e(){
box.style.display="none"//隱藏
}
function f(){
box.style.display="block"//顯示
}
</script>
</head>
<body>
<!-- 用按鈕控制div高度、寬度、顏色、重置、隱藏、顯示 -->
<div id="box"></div>
<input type="button" value="變高" onclick="a()">
<input type="button" value="變寬" onclick="b()">
<input type="button" value="變色" onclick="c()">
<input type="button" value="重置" onclick="d()">
<input type="button" value="隱藏" onclick="e()">
<input type="button" value="顯示" onclick="f()">
</body>
</html>
第一步,先寫好完整的布局結(jié)構(gòu)并命名;
第二步,為需要控制的div擬定不同的方法;
第三步,將方法與div進(jìn)行鏈接
添削の先生:天蓬老師添削時(shí)間:2018-12-23 10:38:18
先生のまとめ:作業(yè)寫的不錯(cuò),不過函數(shù)的命名最好不要用a,b,c等無意義的名字,這樣的代碼是不能放到真實(shí)項(xiàng)目中的。好的編碼習(xí)慣從一開始就要培養(yǎng)