123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <!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: #000;
- }
- </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>
|