要知道添加的是什么事件,比如onclick,onmouseover,你就可以直接这样获得:
var oldbh = obj.onclick;

解决方案 »

  1.   

    TO:dh20156(风之石)
    试过这种情况嘛?
    <html>
    <body >
    <input id=test onfocus="alert();" >
    <input type=button onclick="addfun();" value=addfun >
    <input type=button onclick="detachfun();" value=detachfun >
    <input type=button onclick="getfocus();" value=getfocus ></body>
    </html>
    <script>
    function gg(){
      alert("DD");
    }function addfun(){
      eval("test").attachEvent("onfocus",function(){gg("ddd")});
    }
    function detachfun(){
      eval("test").detachEvent("onfocus",function(){gg()});
    }
    function getfocus(){
      alert(test.onfocus);
    }
    </script>
      

  2.   

    这个东东我也不会,不过象dh20156(风之石)的 obj.onclick 取到的只是 null 呀。
      

  3.   

    <html>
    <body >
    <input id=test  >
    <input type=button onclick="addfun();" value=addfun >
    <input type=button onclick="detachfun();" value=detachfun >
    <input type=button onclick="getfocus();" value=getfocus ></body>
    </html>
    <script>
    function gg(){
      alert("DD");
    }function addfun(){
      eval("test").attachEvent("onfocus",gg);
    }
    function detachfun(){
      eval("test").detachEvent("onfocus",function(){gg()});
    }
    function getfocus(){
      alert(test.onfocus);
    }
    </script>
      

  4.   

    看了一下,除了直接赋值
    aa.onfocus = gg;
    可以
    其他情况都不行
      

  5.   

    我在猜想是不是在执行onfocus的时候,先去判断是否attachEvent的东西
    或者内置了attachEvent所绑定函数的位置
    要不就是绑定到window或者body里面
    但是看了一下.好像body的属性都没有改变,
      

  6.   

    嗯,我估计它应该是把对应的函数句柄赋给了对象的类似于 prototype 之类的一个扩展里了,所以直接调用是调用出来的。
      

  7.   

    这样试试:
    <html>
    <body >
    <input id=test>
    <input type=button onclick="addfun();" value=addfun >
    <input type=button onclick="detachfun();" value=detachfun >
    <input type=button onclick="getfocus();" value=getfocus ></body>
    </html>
    <script>
    function gg(){
      alert("DD");
    }function addfun(){
      //test.attachEvent("onfocus",function(){gg("ggg")});
      test.onfocus = function(){gg("ggg")}
    }
    function detachfun(){
      //test.detachEvent("onfocus",function(){gg()});
      test.onfocus = null;
    }
    function getfocus(){
      alert(test.onfocus);
    }
    </script>
      

  8.   

    ”嗯,我估计它应该是把对应的函数句柄赋给了对象的类似于 prototype 之类的一个扩展里了,所以直接调用是调用出来的。“同意梅大的看法!
      

  9.   

    引用:
      嗯,我估计它应该是把对应的函数句柄赋给了对象的类似于 prototype 之类的一个扩展里了,所以直接调用是调用出来的。如果照这么说,不是应该在属性里面也可以看出来呢?
    这里有一段qiushuiwuhen的代码
    倒是可以看到属性变化的,改改应该可以
     但是咋的就看不出来呢?
    <input id=test>
    <textarea id=show ></textarea>
    <script>
    var tag="test",count=0;
    for(evt in eval(tag)){
    if(evt.substr(0,2)=="on")
    eval(tag+"."+evt+"=new Function('run()')");
    }
    function run(){
      str=(++count)+"."+tag+"的"+event.type+"事件\n"
      for(obj in event)if(eval("event."+obj)){
          str+="   " + obj+":"+eval("event."+obj)+"\n";
      }
      show.value=str+show.value;
    }
    </script>
      

  10.   

    仔细看了一下秋水的代码,eval(tag+"."+evt+"=new Function('run()')");
    这句代码不就等同于 eval(tag +"."+ evt +"=function(){run()}");  吗?
    还是直接赋函数的吗,不是 attachEvent
      

  11.   

    呵呵,我贴这段代码不是说证明这段代码是用什么方式绑定run的
    而是让大家看看test对象的属性变化
    在动态attachEvent给对象的时候,有没有属性发生变化
    至少从目前看来是没有变化的