摘要:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>changeDIV</title> <style type="text/css"> #box{width: 
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>changeDIV</title> <style type="text/css"> #box{width: 100px;height: 100px;background: red;margin: 20px 80px;} </style> </head> <body> <!-- 用按钮控制div高度,宽度,颜色,重置,隐藏,显示 --> <script type="text/javascript"> var box window.onload=function () { box=document.getElementById('box'); } function chageHeight(){ box.style.height="400px" //改变高度 } function chageWidth(){ box.style.width="400px" //改变宽度 } function chageColor(){ box.style.background="pink" //改变颜色 } function resetting(){ //重置div样式 box.style.height="100px" box.style.width="100px" box.style.background="red" } function hidden(){ //隐藏DIV box.style.display="none" } function display(){ //显示DIV box.style.display="block" } </script> <div id="box"></div> <input type="button" value="变高" onclick="chageHeight()"> <input type="button" value="变宽" onclick="chageWidth()"> <input type="button" value="变色" onclick="chageColor()"> <input type="button" value="重置" onclick="resetting()"> <input type="button" value="隐藏" onclick="hidden()"> <input type="button" value="显示" onclick="display()"> </body> </html>
一开始代码没有错误,但是JS代码不生效,之后重置了下浏览器,就可以了
批改老师:灭绝师太批改时间:2018-11-07 09:05:50
老师总结:可能是缓存问题,测试代码的时候可以选择在电脑上安装2款以上浏览器