abstract:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>javascript控制DIV樣式</title> <style type="text/css"> #box{width:&n
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>javascript控制DIV樣式</title> <style type="text/css"> #box{width: 100px; height: 100px; background: #ccc; margin: 30px 90px;} </style> </head> <body> <div id="box"></div> <button onclick="ChangeHeight()">改變高度</button> <button onclick="ChangeWidth()">改變寬度</button> <button onclick="ChangeColor()">改變顏色</button> <button onclick="reset()">重置</button> <button onclick="conceal()">隱藏</button> <button onclick="show()">顯示</button> <script type="text/javascript"> var box; window.onload=function(){ box=document.getElementById("box") } function ChangeHeight(){ box.style.height="200px" } function ChangeWidth(){ box.style.width="200px" } function ChangeColor(){ box.style.background="pink" } function reset(){ box.style.height="100px" box.style.width="100px" box.style.background="#ccc" } function conceal(){ box.style.display="none" } function show(){ box.style.display="block" } </script> </body> </html>
總結(jié):萬事皆非易事,需多多練習(xí)。
Correcting teacher:天蓬老師Correction time:2019-01-13 17:06:02
Teacher's summary:function ChangeHeight(){
box.style.height="200px"
}其實這里, 用參數(shù)的方式,將box傳遞進(jìn)來比較好,你說呢?