摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>changeDiv</title> <style> #box{width:100px;height:100px; background: 
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>changeDiv</title> <style> #box{width:100px;height:100px; background: red;margin: 20px 80px;} </style> </head> <body> <!-- 用按钮控制div高度、宽度、颜色、重置、隐藏、显示 --> <div id="box"></div> <input type="button" value="变高" onclick="high()" /> <input type="button" value="变宽" onclick="widths()"/> <input type="button" value="变色" onclick="bgColors()"/> <input type="button" value="重置" onclick="homes()"/> <input type="button" value="隐藏" onclick="hiddens()"/> <input type="button" value="显示" onclick="shows()"/> <script type="text/javascript"> var box window.onload = function (){ box = document.getElementById("box"); } function high(){ box.style.height ="400px"; //高度 } function widths(){ box.style.width ="400px"; //宽度 } function bgColors(){ box.style.background ="pink"; //颜色 } function homes(){ box.style.height ="100px"; box.style.width ="100px"; box.style.background ="red"; //重置 } function hiddens(){ box.style.display ="none"; //颜色 } function shows(){ box.style.display ="block"; //颜色 } </script> </body> </html>