码迷,mamicode.com
首页 > 其他好文 > 详细

this的指向(慢慢添加)

时间:2016-12-24 14:19:37      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:rip   document   pre   line   click   函数   show   time   height   

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>










 

this的指向(慢慢添加)

标签:rip   document   pre   line   click   函数   show   time   height   

原文地址:http://www.cnblogs.com/laraLee/p/6217146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!