12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- #box1 {
- width: 300px;
- height: 300px;
- background-color: aqua;
- }
- </style>
- </head>
- <body>
- <div id="box1"></div>
- <script>
- var box1 = document.getElementById("box1");
- // 1.点击事件 this指向当前点击元素
- // box1.onclick = function() {
- // console.log(this);
- // }
- // 2.定时器 this指向window
- // var timer = setInterval(function(){
- // // console.log(this);
- // box1.onclick = function() {
- // console.log(this);
- // }
- // },1000)
- // 3.对象 this指向当前对象
- // var obj = {
- // name:"LiLi",
- // age: 10,
- // eat:function() {
- // console.log(this);
- // }
- // }
- // obj.eat();
- // 4.函数 this指向window
- function fn1() {
- console.log(this)
- }
- fn1()
- </script>
- </body>
- </html>
|