12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <!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>
- #box {
- width: 200px;
- height: 200px;
- background-color: #f00;
- }
- </style>
- </head>
- <body>
- <div id="box"></div>
- <script>
- var box = document.getElementById("box");
- // 1.点击事件 this指向该对象
- // box.onclick = function() {
- // console.log(this)
- // }
- // 2.定时器 this指向window
- // setTimeout(()=> {
- // console.log(this)
- // },2000)
- // box.onclick = function () {
- // setTimeout(() => {
- // console.log(this)
- // }, 2000)
- // }
- // setInterval(定时器) / setTimeout(延时器)
- // 3.对象中 普通函数 调用本身;箭头函数调用 上下级
- // let obj = {
- // name:"图图",
- // age:3,
- // address:function() {
- // console.log(this,'语音')
- // }
- // }
- // obj.address();
- // 4.普通函数 this指向window
- function fn() {
- console.log(this)
- }
- fn()
- </script>
- </body>
- </html>
|