22.this指向.html 916 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. #box {
  9. width: 300px;
  10. height: 300px;
  11. background: #00f;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <div id="box"></div>
  17. <script>
  18. var box = document.getElementById("box");
  19. // box.onclick = function() {
  20. // console.log(this);
  21. // }
  22. // box.onclick = function() {
  23. // setInterval(function(){
  24. // console.log(this)
  25. // },1000)
  26. // }
  27. // var obj = {
  28. // a:"1",
  29. // b:function() {
  30. // console.log(this)
  31. // }
  32. // }
  33. // obj.b();
  34. function fn1() {
  35. console.log(this);
  36. }
  37. fn1();
  38. </script>
  39. </body>
  40. </html>