<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title></title>
<style type="text/css"></style> <script type="text/javascript"> function P()
{
    alert(event.srcElement.tagName);
// 这个是发生事件时候,获取鼠标指向的对象.例如:<INPUT>。 如何才能获取被绑定事件对象 <DIV> 呢?
// 就是说我在按钮控件上点击,获取真正被绑定事件的对象(DIV)。怎么做到? this 不行啊。this在IE中是window对象。
}
</script>
</head>
<body><div onclick="P()" id="my1" style="width:200px;height:100px;border:1px solid red;background:#eee" >     <input type="button" value="Button" /></div>
</body>
</html>

解决方案 »

  1.   

    这样?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
        <title> </title> 
    <style type="text/css"> </style> 
    <script type="text/javascript"> 
        
    function P() 

    var obj = event.srcElement;
    var funName = arguments.callee.toString().match(/^function\s*(\w+\(\))/i)[1];
    while(obj && obj.onclick == null && obj.getAttribute("onclick") == null ){
     obj = obj.parentNode;
    }
    if(obj.onclick == arguments.callee|| obj.getAttribute("onclick") == funName){
    alert(obj.tagName);
    }else{
    alert("没找到");
    }
    // 这个是发生事件时候,获取鼠标指向的对象.例如: <INPUT>。 如何才能获取被绑定事件对象 <DIV> 呢? 
    // 就是说我在按钮控件上点击,获取真正被绑定事件的对象(DIV)。怎么做到? this 不行啊。this在IE中是window对象。 

        
        window.onload = function(){
            document.getElementById("my2").onclick = P;
        };
        
        </script> 
    </head> 
    <body> <div onclick="P()" id="my1" style="width:200px;height:100px;border:1px solid red;background:#eee" > 
        <input type="button" value="Button" /> 
    </div> <div id="my2" style="width:200px;height:100px;border:1px solid red;background:#eee" > 
        <input type="button" value="Button" /> 
    </div> 
    </body> 
    </html>