zoukankan      html  css  js  c++  java
  • this的指向(慢慢添加)

    this的指向:

    1.行间调用函数:

       <div id="div1" onclick="show()"></div>
      <script>
          function show(){
            alert(this); //object window;
          }
      </script>

    2. 定时器
    <div id="div1"></div>
      <script>
    var oDiv=document.getElementById('div1');
    oDiv.onclick=function(){
                 setTimeout(function(){
    alert(this); //window;
    },1000);
    };
      </script>

    3. 函数调用
       <div id="div1"></div>
      <script>
        function show(){
            alert(this);
        }
        document.getElementById('div1').onclick=function(){
            show(); //window;
        }
    </script>
    4. 不是函数调用
       
        
    <div id="div1"></div>
      <script>
       
        document.getElementById('div1').onclick=function(){
            alert(this); //DIV
        }
    </script>









    
    
     
  • 相关阅读:
    django学习----http协议
    线程进程和协程
    内置函数
    我所了解的递归
    函数的闭包和装饰器
    字符串的内置方法
    格式化输入输出
    逻辑运算符和操作运算符
    python流程控制
    计算机网络原理
  • 原文地址:https://www.cnblogs.com/laraLee/p/6217146.html
Copyright © 2011-2022 走看看