<head> 
<style> 
#floater { 
position: absolute; 
left: 500; 
top: 146; 
width: 125; 
visibility: visible; 
z-index: 10 

</style> 
</head> 
<body id="body1"> 
<div ID="floater" style="left: 500px; top: 158px"> 
<p id="p1" align="center"> <img id="img1" SRC="1.gif" alt="图片显示的文字" WIDTH="125" HEIGHT="60"> <br> 
<font color="#FF8040">2008北京欢迎你 </font> </p> 
</div> 
<script> 
if(document.all) 

  document.onmousedown = grabIt; 

function grabIt(e) 

  if(document.all) 
  { 
    whichIt = event.srcElement; 
    alert(whichIt.id);
    alert(whichIt.parentElement.id);
  } 

</script> 
</body>
细看

解决方案 »

  1.   

    我要的就是whichIt = event.srcElement事件源对象和它的父对象
    就要下面两个输出来看看:理论上下面两个是不等的,但是事实是相等的。
    就问这个为什么???????
    alert(whichIt) 
    alert(whichIt.parentElement)
      

  2.   

    相等?
    我这里显示一个[object]一个null
      

  3.   

    <!DOCTYPE html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head> 
    <style> 
    #floater { 
    position: absolute; 
    left: 500; 
    top: 146; 
    width: 125; 
    visibility: visible; 
    z-index: 10 

    </style> 
    </head> 
    <body> 
    <div ID="floater" style="left: 500px; top: 158px"> 
    <p align="center"> <img SRC="1.gif" alt="图片显示的文字" WIDTH="125" HEIGHT="60"> <br> 
    <font color="#FF8040">2008北京欢迎你 </font> </p> 
    </div> 
    <script> 
    if(document.all) 

      document.onmousedown = grabIt; 

    function grabIt(e) 

      if(document.all) 
      { 
        whichIt = event.srcElement; 
        alert(whichIt) 
        alert(whichIt.parentElement) 
      } 

    </script> 
    </body>
    </html>
      

  4.   

    不是连续显示两个[body]怎么回事?
      

  5.   

    event.srcElement是发生事件的元素
    whichIt.parentElement是发生事件元素的父元素,怎能相等?
    看id
      

  6.   

    是不等的两个元素哎,但运行后alert(whichIt)和alert(whichIt.parentElement)打印出来的却是两个[body],这是怎么回事呢????为什么第一个alert值和第二个alert值输出的都是[body]字串????
      

  7.   

    你单击图片上看看是不是显示:一个[object]一个[object],单击图片区域以外就是你说的那种情况:显示一个[object]一个null 
      

  8.   

    orz
    看我的名字,服特,呵呵
    object是对象啊,都叫你运行我的例子了,不信
      

  9.   

    我现在就要输出对象:看它是什么。不要输出它的Id属性,OK!alert(whichIt.id);alert(whichIt.parentElement.id);
      

  10.   

    这里指出一点,如果你用的是ie或者是其他的浏览器,得到的结果是不一样的,你用因为parentElement只是支持ie,它会得到不同的内容,而如果你换成用其他,当然我没有完全试过,好久以前试过,就会得到不同点内容了,,其实也就是一句话,他的指向不同和支持不同,如果你用parentNode来换一换就知道了.当然还有其他的方式.呵呵,个人意见,你可以试试,仅仅是个人意见.
      

  11.   

    event.srcElement是发生事件的元素
    这个发生事件的元素是document吗?
    whichIt.parentElement是发生事件元素的父元素
    那这个父元素是谁,是window吗,为什么点击图片和其他地方结果不一样。

      

  12.   

    似乎了解了些当你点击某个点的时候这个
    event.srcElement是不同的<img>标签有父元素
    而document没有。
      

  13.   

    打印出来就清楚了,这种ie only的属性还是少用为好,parentNode完全能解决好多问题
    <head>
    <style>
    #floater {
    position: absolute;
    left: 500;
    top: 146;
    width: 125;
    visibility: visible;
    z-index: 10
    }
    </style>
    </head>
    <body>
    <div ID="floater" style="left: 500px; top: 158px;border:1px solid red;">
        <p align="center">
            <img SRC="http://www.baidu.com/img/baidu_logo.gif" alt="图片显示的文字" WIDTH="125" HEIGHT="60"><br/>
            <font color="#FF8040">2008北京欢迎你 </font> 
        </p>
    </div>
    <font color="#FF8040">2008北京欢迎你 </font> 
    <script>
    if(document.all)
    {
      document.onmousedown = grabIt;
    }
    function grabIt(e)
    {
      if(document.all)
      {
        whichIt = event.srcElement;
        alert(whichIt.innerHTML)
        alert(whichIt.parentElement.innerHTML)
      }
    }
    </script>
    </body>
      

  14.   

      if(document.all) 
      { 
        whichIt = event.srcElement; 
        alert(whichIt.tagName); 
        alert(whichIt.parentElement);
      } 
    这个试试,呵呵。