parent element ->父元素

解决方案 »

  1.   

    bencalie(Bencalie):谢谢!能否举个例子?
      

  2.   

    <table><tr id="parent"><td onclick="alert(this.parentElement.id)">onlick</td></tr></table>
    tr就是td的父元素。
      

  3.   

    刚才给你写了一个例子,希望你能看明白<body id="BodyElement" style="margin:10px">
    <br>
    这个是Body,ID=BodyElement
    <div id=DivElement style="border:1px blue solid;">
    这个是DIV,ID=DivElement
    <span id=GreenSpan style="width:200px;height:100px;border:1px green solid">
    这个是SPAN,ID=GreenSpan
    </span>
    <span id=RedSpan style="width:300px;height:300px;border:1px red solid">
    这个是SPAN,ID=RedSpan
    </span>
    </div>
    <textarea id=TextAreaElement style="width:700px;height:100px;overflow:auto"></textarea>
    <script language="Jscript">
    function document::onmousemove(){
    TextAreaElement.value="当前Element:\t"+event.srcElement.id+"\n当前Element的父Element:\t"+event.srcElement.parentElement.id+"\nevent.x:\t"+event.x
    }
    </script>
    </body>
      

  4.   

    请看代码<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body onmousemove="window.status = 'X=' +  window.event.x + ' Y=' + window.event.y">
    <table width="500" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <br>
    <table width="500" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <form name="form1" method="post" action="">
      <input name="textfield" type="text" size="50">
      <br>
      <br>
      <textarea name="textfield2" cols="50" rows="15"></textarea>
      <br>
      <br>
      <input type="submit" name="Submit" value="Submit">
    </form>
    </body>
    </html>地址栏显示的值都是相对于左上角的,那么a relatively positioned parent element是什么?
      

  5.   

    window.event.x和window.event.clientX有什么区别?
      

  6.   

    给你个代码比较一下,比看书和问人都好。
    <HTML> 
    <HEAD> 
    <TITLE>键盘和鼠标事件测试</TITLE> 
    <script language="javascript"> 
    function keyDown(e) {
      s = event.srcElement.tagName+"<br>";
      for(v in event)
        s += v+"="+event[v]+"<br>";
      view.innerHTML = s;
    sss.innerHTML = event.screenX+","+event.screenY;
    return false;

    document.onkeydown=keyDown 
    document.onkeyup=keyDown 
    document.onmousedown=keyDown 
    document.onmouseup=keyDown 
    document.onmousemove=keyDown 
    document.onmouseover=keyDown 
    document.onmouseout=keyDown 
    document.onkeypress=keyDown 
    </script> 
    </HEAD> <BODY> 
    <p>请操作鼠标或键盘</p> <input type=text><span id="sss"></span>
    <table border>
    <tr><td>123</td><td>abc</td></tr>
    </table>
    <span id="view"></span>
    </BODY> 
    </HTML> 
      

  7.   

    对于这个问题,我现在基本明白了。event.x
    This property returns the x-coordinate of the closest relatively positioned parent element of the element that fires the event. If the event firing element is relatively positioned, then the x-coordinate from the boundary of the element is returned. If the event firing element and all of its parent elements are not relatively positioned, then the x property returns a coordinate relative to the body element.通过此贴,我知道了很多问题之外的东西,特别感谢Go_Rush(阿舜)、xuzuning(唠叨)!!!此贴加到50分,结贴!