【【【【【【怎么获取相对当前光标所在位置的最近的特定的父节点?】】】】】】 补充:需要获得这个<td>里的所有内容。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先谢谢楼上的。我在描述一下:“|”---表示光标“...”---表示其他html源码<td ...>...<td ...>...<td ...>.........<!--注:我想获得和光标最邻近的这个父节点td的源码--> <td ...> ... ... ........................|.............. ... ... </td>...</td>...</td>...</td> 好象只有输入框有光标吧,table里有光标?还有你最近是什么意思,表示包含光标的对象么 <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> 在编辑状态下table里好象也有光标,就上面的例子看,有4个<td>包含了光标对象,我只需要下面的td源码: <td ...> ... ... ........................|.............. ... ... </td> 也就是说,我需要光标所在位置的父<td>的源码 也就是,光标是<td>的孩子,而不是孙子,呵呵。 <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> <!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> window.external.GetAddress。。。。是获取当前地址吗? jquery 疑问 哪位高手帮我详细解答一下一条正则表达式 ? 帮忙修改click为mouseover与mouseout的效果。 IE FF兼容的带时间日期输入控件 请问大家 如果我想得到 被包含在div id里面的 div该怎么实现啊 ?? 通过web方式能对sqlserver 2000进行数据备份吗? 可以对js的文件进行加密吗?? 怎样能够在系统处理之后处理按键消息 两个小问题 一个js 的函数如何在页面打开时的“某个地方”执行 如何判断一个叶面加载已经完成?
“...”---表示其他html源码<td ...>
...<td ...>
...
<td ...>
...
...
...
<!--注:我想获得和光标最邻近的这个父节点td的源码-->
<td ...>
...
...
........................|..............
...
...
</td>
...
</td>
...
</td>
...
</td>
<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>
<td ...>
...
...
........................|..............
...
...
</td>
<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>
<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>