补充:需要获得这个<td>里的所有内容。

解决方案 »

  1.   

    先谢谢楼上的。我在描述一下:“|”---表示光标
    “...”---表示其他html源码<td ...>
    ...<td ...>
    ...
    <td ...>
    ...
    ...
    ...
    <!--注:我想获得和光标最邻近的这个父节点td的源码-->
      <td ...>
      ...
        ...
         ........................|..............
        ...
      ...
      </td>
    ...
    </td>
    ...
    </td>
    ...
    </td>
      

  2.   

    好象只有输入框有光标吧,table里有光标?还有你最近是什么意思,表示包含光标的对象么
      

  3.   

    <TABLE id=tbl cellSpacing=1 cellPadding=1 border=1>
    <TBODY>
    <TR>
    <TD width=100 id=td1>This is Line1</TD></TR>
    <TR>
    <TD width=100 id=td2>This is Line2</TD></TR>
    <TR>
    <TD width=100 id=td3>This is Line3</TD></TR>
    </TBODY>
    </TABLE>
    <script>
    document.onclick=function() {
      alert(document.activeElement.id)
    }
    </script>
      

  4.   

    在编辑状态下table里好象也有光标,就上面的例子看,有4个<td>包含了光标对象,我只需要下面的td源码:
      <td ...>
      ...
        ...
         ........................|..............
        ...
      ...
      </td>
      

  5.   

    也就是说,我需要光标所在位置的父<td>的源码
      

  6.   

    也就是,光标是<td>的孩子,而不是孙子,呵呵。
      

  7.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><body>
      <table border="1" id=containerTable>
        <tr>
          <td><input ></td>
          <td><span><span><div><input></div></span></span></td>
          <td>fdsfd</td>
        </tr>
      </table>
      
      <input>
    </body></html>
    <script language=javascript>
    function getFocusTd()
    {
    var theActiveObj=document.activeElement;
    if(theActiveObj==null || !containerTable.contains(theActiveObj)) return false;
    var theTd=theActiveObj.parentElement;
    var i=0;//避免死循环
    while( theTd.tagName!="TD" && i++<10 )
    {
    theTd=theTd.parentElement;
    }
    alert(theTd.outerHTML);}window.setInterval("getFocusTd()",2000)
    </script>
      

  8.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title> New Document </title>
    <meta name="Generator" content="EditPlus">
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    <script language="JavaScript">
    <!--
    var o;
    document.onmousedown = function () 
    {
    o = document.elementFromPoint(event.x, event.y);
    }
    document.onkeydown = function ()
    {
    if(event.keyCode ==13)
    {
    alert(o.outerHTML);
    }
    event.returnValue = 0;
    }//-->
    </script>
    </head><body contentEditable onload="o=document.body;">
    <TABLE id=tbl cellSpacing=1 cellPadding=1 border=1>
    <TBODY>
    <TR>
    <TD width=100 id=td1 onfocus="alert();">This is Line1</TD></TR>
    <TR>
    <TD width=100 id=td2>This is Line2</TD></TR>
    <TR>
    <TD width=100 id=td3>This is Line3</TD></TR>
    </TBODY>
    </TABLE>
    </body>
    </html>