窗口和alert()对话框是两个不同的窗口,它们共用同一个缓存来存储事件值,当alert()对话框出现后,alert()中的事件更新了原窗口中的事件内容,所以你的event.srcElement值为null.

解决方案 »

  1.   

    不是这个原因,不用alert函数也是同样即:
    var timerID = 0;
    function testfn( i )
    {
    if ( i -- > 0 )
    {
    timerID = window.setTimeout("testfn(" + i + ")", 500);
    }
    else
    {
    window.clearTimeout( timerID );
    dofn();
    }
    }function dofn()
    {
    alert( "event.srcElement" + event.srcElement.tagName  );
    }testfn(2);该函数的功能是让testfn延迟i秒,在执行dofn函数
    但在dofn中的event仍然为null;
      

  2.   

    setTimeout本身就是一个时间触发事件,当它触发后,也要更新event的内容不信你将:timerID = window.setTimeout("testfn(" + i + ")", 500);改为:timerID = window.setTimeout("dofn()", 500);
    试试.肯定出错.
      

  3.   

    setTimeout() does not trigger an event, so window.event is null inside the function called by setTimeout
      

  4.   

    karma tell me: event called by setTimeout. so event is null
      

  5.   

    应该是window.event只传给事件处理函数当无处理函数或事件处理完毕时,window.event就=null要保持event的值,只能在事件处理函数中 赋给全局变量