2_demo.html 774 B

12345678910111213141516171819202122232425262728293031323334
  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: aqua;
  13. left: 300px;
  14. top: 50px;
  15. position: absolute;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <div id="div1"></div>
  21. <button class="btn">变换位置</button>
  22. <script>
  23. var div1 = document.getElementById('div1')
  24. var btn = document.getElementsByClassName('btn')
  25. btn[0].onclick = function(){
  26. // console.log(111)
  27. div1.style.left = 700 + 'px'
  28. div1.style.top = '200px'
  29. div1.style.background = 'red'
  30. }
  31. </script>
  32. </body>
  33. </html>