12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- #div1{
- width: 200px;
- height: 200px;
- background: aqua
- }
- </style>
- </head>
- <body>
- <div id="div1"></div>
- <script>
- var div1 = document.getElementById('div1')
- //1.当前对象引用中 谁的事件 this就指向谁
- // div1.onclick = function(){
- // console.log(this)
- // }
-
- //2.在定时器中 this->window
- // var timer = setInterval(function(){
- // console.log(this)
- // },1000)
- // div1.onclick = function(){
- // var timer = setInterval(function(){
- // console.log(this)
- // },1000)
- // }
-
- //3.对象下面 this->对象本身
- // var person = {
- // name: 'zs',
- // age: 18,
- // eat: function(){
- // console.log(this)
- // }
- // }
- // person.eat()
- //4.方法里面 this->window
- function xx(){
- console.log(this)
- }
- xx()
- </script>
- </body>
- </html>
|