2_练习.html 989 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. #div1 {
  10. width: 200px;
  11. height: 200px;
  12. background: red;
  13. top: 200px;
  14. left: 100px;
  15. position: absolute
  16. }
  17. </style>
  18. <script>
  19. //等页面所有的东西全部加载完毕,执行里面的内容
  20. // window.onload = function () {
  21. // var btn = document.getElementById('btn')
  22. // console.log(btn)
  23. // }
  24. </script>
  25. </head>
  26. <body>
  27. <button id="btn">点击</button>
  28. <div id="div1">
  29. </div>
  30. <script>
  31. var btn = document.getElementById('btn')
  32. console.log(btn)
  33. // var div1 = document.getElementById('div1')
  34. // btn.onclick = function(){
  35. // div1.style.background = 'blue'
  36. // div1.style.top = '400px'
  37. // div1.style.left = '250px'
  38. // }
  39. </script>
  40. </body>
  41. </html>