2_练习.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. <!-- <ul>
  30. <li>1</li>
  31. <li>2</li>
  32. <li>3</li>
  33. </ul> -->
  34. </div>
  35. <script>
  36. var btn = document.getElementById('btn')
  37. console.log(btn)
  38. var div1 = document.getElementById('div1')
  39. // btn.onclick = function(){
  40. // div1.style.background = 'blue'
  41. // div1.style.top = '400px'
  42. // div1.style.left = '250px'
  43. // }
  44. var uli = document.getElementsByTagName('li')
  45. for (var i = 0; i < uli.length; i++) {
  46. uli[i].index = i
  47. console.log(uli[2].index)
  48. }
  49. div1.onmousemove = function(){
  50. console.log(123)
  51. }
  52. div1.onmouseout = function(){
  53. console.log('我溜了')
  54. }
  55. </script>
  56. </body>
  57. </html>