<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0011)about:blank -->
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
window.document.body.attachEvent( 'onclick' ,t ); function t(){ alert( 'this:' +  typeof this ); }
alert(typeof t)
alert(typeof window.document.body)
//-->
</SCRIPT>
</BODY></HTML>

解决方案 »

  1.   

    经测试this就是o点击的时候typeof this是object然而typeof t是function
      

  2.   

    不是的,this.tagName是弹不出来的
    我感觉应该是window对象,从下面的代码中可以看出
    <input name=o>
    <script language=javascript>
    o.attachEvent( 'onclick' ,t ); function t(){ for(var i in this){alert(i)}alert( 'this:' + this ); } 
    </script>
      

  3.   

    不是o,这个我测试过的。是window对象,倒有可能,怎么测试呢?那在function t中如何得到 o 和 t对象(函数)本身呢?
      

  4.   

    得到O对象简单,只要不要写this,可以按下面的写法写,闭包问题,前几天刚有帖子
    <input name=o>
    <script language=javascript>
    a=document.getElementById("o")
    o.attachEvent( 'onclick' ,t ); function t(){alert( 'this:' + a.tagName ); } 
    </script>
      

  5.   

    嗯,应该是返回onclick时作用对象的类型,在FF里有很明显的表现<html><head>
    <title>get this</title>
    <script type="text/javascript">
    function t()
    {
      alert('this'+this);
    }window.onload=function(){
    var o=document.getElementById('o');
    //o.attachEvent('onclick',t);
    o.addEventListener('click',t,false);
    }
    </script>
    </head><body>
    <input type="button" id="o" value="click" />
    </body></html>alert出“this[object HTMLInputElement]”
      

  6.   

    IE的情况也可以测试的,下面偷懒了:)
    因为是window对象,最好用两个window对象更清晰一些
    <input name=o>
    <script language=javascript>
    o.attachEvent( 'onclick' ,t ); function t(){this.onload=function(){alert('hehe')} } 
    t()
    </script>
      

  7.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!-- saved from url=(0011)about:blank -->
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=unicode">
    <META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
    <BODY>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    window.document.body.attachEvent( 'onclick' ,t ); function t(){ alert( 'this:' +  typeof this ); alert(this==top)}
    alert(typeof t)
    alert(typeof window.document.body)
    //-->
    </SCRIPT>
    </BODY></HTML>
      

  8.   

    能否不借助
    document.getElementById  、 document.getElementsByName
    在function t中如何得到 o 和 t对象(函数)本身呢?
      

  9.   

    o.setAttribute( 'onclick' ,t );
    o.onclick= function(){ alert( 'this:' + this ); }
      

  10.   

    判断一下就知道了。<input name=o>
    <script language=javascript>
    o.attachEvent( 'onclick' ,t ); function t(){alert(this==window) } 
    </script>
      

  11.   

    document.getElementById  、 document.getElementsByName
    在function t中如何得到 o 和 t对象(函数)本身呢?
    ---------------------
    <input name=o>
    <script language=javascript>
    o.onclick=function(){
    alert(this.tagName);
    }
    </script>
      

  12.   

    我是指:
    o.attachEvent( 'onclick' ,t ); 
    怎么在t里得到o对象?
      

  13.   

    http://www.javaeye.com/topic/24457o.attachEvent( 'onclick' ,t ); 这种方式实际上是
    o.attachEvent( 'onclick' ,function(){t()} ); 
    它只是在o的onclick事件中调用了t(),而不是copy函数t给o对象.所以alert出来的this实际上是window对象
      

  14.   

    <html>
    <body>
    <input type="button" id="bt" value="OK" />
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var bt = document.getElementById("bt");
    bt.attachEvent("onclick", t);
    function t()
    {
        alert(this.location); //很明显,这里的 this 被指向了 window 对象
    }
    //-->
    </SCRIPT>
    </body>
    </html>在JS里那些无主的 this 都是暗指向 window 对象了。<html>
    <body>
    <input type="button" id="bt" value="OK" />
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var bt = document.getElementById("bt");
    bt.attachEvent("onclick", t);
    function t(e)
    {
        e = window.event || e;
        var obj = e.srcElement || e.target;  //这样的写法可兼容所有浏览器
        alert(obj.value);
    }
    //-->
    </SCRIPT>
    </body>
    </html>
      

  15.   

    o.onclick = t;
    function t()
    {
      alert(this);
    }
    这样写 这里的this就是o。。
      

  16.   

    bt.attachEvent("onclick", t);
    function t(e)
    {
        e = window.event || e;
        var obj = e.srcElement || e.target;  //这样的写法可兼容所有浏览器
        alert(obj.value);
    }
    click之后那个形式参数e是什么啊?
      

  17.   

    是什么对象啊?
    只有attachEvent方法加入后在触发才有e么?
      

  18.   

    呵..早的帖子的说..
    哈..不过是通过这个帖子学的兼容..event