1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    2. "http://www.w3.org/TR/html4/loose.dtd">
    3. <html>
    4. <head>
    5. <title>15Style属性练习</title>
    6. <script type="text/javascript">
    7. //页面打开以后就加载
    8. window.onload = function () {
    9. var box1 = document.getElementById("box1");
    10. //设置div的宽高
    11. box1.style.height = "50px";
    12. box1.style.width = "50px";
    13. //把div背景色设置成蓝色
    14. box1.style.backgroundColor = "blue";
    15. //div往下偏移 100px
    16. box1.style.marginTop = "100px";
    17. };
    18. </script>
    19. </head>
    20. <body>
    21. <div id = "box1">
    22. </div>
    23. </body>
    24. </html>