abstrak:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>課后練習-JavaScript控制DIV樣式</title> <style type="text/css"> #box{wid
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>課后練習-JavaScript控制DIV樣式</title> <style type="text/css"> #box{width: 100px;height: 100px;background: red;margin:20px 80px;} </style> </head> <body> <script type="text/javascript"> var box window.onload=function () { box=document.getElementById('box'); } function changeHeight() { box.style.height="400px"; } function changeWidth() { box.style.width="400px"; } function changeBackgroundColor() { box.style.background="#4f0"; } function reset() { box.style.height="100px"; box.style.width="100px"; box.style.background="red"; } function hide() { box.style.display="none"; } function show() { box.style.display="block"; } </script> <div id="box"></div> <input type="button" value="變高" onclick="changeHeight();"> <input type="button" value="變寬" onclick="changeWidth();"> <input type="button" value="變色" onclick="changeBackgroundColor();"> <input type="button" value="重置" onclick="reset();"> <input type="button" value="隱藏" onclick="hide();"> <input type="button" value="顯示" onclick="show();"> </body> </html>
Guru membetulkan:韋小寶Masa pembetulan:2019-02-21 17:26:44
Rumusan guru:寫的很不錯 js來控制div的樣式還是很靈活的