IE好象可以用window.event.srcElement知道事件源。但有更通用的方法吗?不限制在某浏览器的

解决方案 »

  1.   

    如果用this给函数。那就就相当于要在许多标签设置属性了。我要做的是一个函数通用的控制所有标签。我给IE的例子吧:
    <html>
    <head>
    <script>
    function a(){
    var obj=window.event.srcElement;
    obj.style.boundColor="#eeeeee";
    }
    b(){
    var obj=window.event.srcElement;
    obj.style.boundColor="#eeeeee";
    }
    </script>
    <body onmouse="a();" onmouseout="b();">
    ............//里面为未知或者动态的内容,无法预先确知;
    </body></html>
    //这段代码可以使BODY下的所有元素在鼠标移入、移出时执行相应程序;
    //类似的如何设计这种获取某节点下的子树的节点都修改属性的方法?
      

  2.   

    <html>
    <head>
    <script>
    function CheckObj(){ for(i=0;i<mybody.children.length;i++){
    mybody.children(i).attachEvent("onmouseover",function(){moveWithOptions("#FF0000","#0000FF")});
    mybody.children(i).attachEvent("onmouseout",function(){moveWithOptions("","")});
    }
    function moveWithOptions(backgroundColor,textColor) {
    with(event.srcElement) {
    style.background = backgroundColor;
    style.color = textColor;
    }
    }
    }
    </script>
    <body id="mybody" onload="CheckObj()">
    <INPUT TYPE="text" NAME="testInputText" value="testInputText">
    <INPUT TYPE="button" NAME="testInputbutton" value="testInputbutton">
    <INPUT TYPE="checkbox" NAME="testInputcheckbox" value="testInputcheckbox">
    <a href="#" NAME="tagA" >tagA</a>
    <span>tagSpan</span>
    <TABLE>
    <TR>
    <TD>td_1</TD>
    <TD>td_2</TD>
    </TR>
    </TABLE>
    </body></html>