12345678910111213141516171819202122232425262728293031323334353637383940 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <div id="box1">12</div>
- <script>
- var box1 = document.getElementById("box1");
- // 点击事件 this指向当前点击对象
- box1.onclick = function() {
- console.log(this);
- }
- // 定时器 this指向window
- // var timer = setInterval(()=>{
- // console.log(this,'定时器')
- // },1000)
- // 对象中 当前对象
- var person = {
- name:"孙悟空",
- age:18,
- say:function() {
- console.log(this);
- }
- }
- person.say();
- // 函数 this指向window
- function fn1() {
- console.log(this);
- }
- fn1()
- </script>
- </body>
- </html>
|