怎么获得html页面中,相同级别得节点对象(up者有分)?

llhdf 2004-11-23 03:41:23
<table id="tab1">
<tr>
<td>
<input type="text" name="t1" value="" onClick="例如在这,怎么获得节点t2对象得引用">
</td>
<td>
<input type="text" name="t2" value="t22">
</td>
</tr>
</table>
请问怎么从对象t1,直接获得下一个元素对象t2,我看了javascript中有parentElement获得上级节点元素,但是我没有发现获得同级节点元素得方法,请问怎么获得同级别得对象?
如果实在不行,是不是只有用parentElement.child在遍历下面得节点了。
...全文
161 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
llhdf 2004-12-01
  • 打赏
  • 举报
回复
谢谢,各位!
littleboys 2004-12-01
  • 打赏
  • 举报
回复
document.all.t1.parentNode.nextSibling.childNodes[0].value
littleboys 2004-12-01
  • 打赏
  • 举报
回复
<FORM METHOD=POST ACTION="">
<table id="tab1">
<tr>
<td>
<input type="text" name="t1" value="" onClick="getValue();">
</td>
<td><span id='t2' value="555">id</span>
<input type="text" name="t2" value="t22">
<input type="text" name="t2" value="t23">
</td>
</tr>
</table>
</FORM>

</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--
function getValue()
{
var len = document.all.t1.parentElement.nextSibling.childNodes.length;
for(var i=0;i<len;i++)
{
var nextname =document.all.t1.parentElement.nextSibling.childNodes[i].tagName;
var nextvalue =document.all.t1.parentElement.nextSibling.childNodes[i].value;
alert("name="+nextname+"nextvalue="+nextvalue);

}

}
//-->
</SCRIPT>
littleboys 2004-12-01
  • 打赏
  • 举报
回复
同意楼上
document.all.t1.parentElement.nextSibling.childNodes[0].value
phoubes 2004-12-01
  • 打赏
  • 举报
回复
<table id="tab1">
<tr>
<td>
<input type="text" name="t1" value="" onClick="alert(this.parentElement.nextSibling.childNodes[0].tagName);">
</td>
<td>
<input type="text" name="t2" value="t22">
</td>
</tr>
</table>
llhdf 2004-12-01
  • 打赏
  • 举报
回复
up *******************************看楼上******************************
llhdf 2004-11-26
  • 打赏
  • 举报
回复
up *******************************看楼上******************************
llhdf 2004-11-26
  • 打赏
  • 举报
回复

大家帮看看,为什么不行?
<BODY>
<input type="text" name="t1">
<input type="text" name="t2">
<BODY>
<SCRIPT>
// returns the list item labeled 'List Item 2'
var oSibling = t1.nextSibling;
alert(oSibling.tagName);
</SCRIPT>
JK_10000 2004-11-24
  • 打赏
  • 举报
回复
<table id="tab1" border="1">
<tr>
<td>
<input type="text" name="t1" onClick="alert(this.parentElement.parentElement.all.t2.value)" value="t1">
</td>
<td>
<input type="text" name="t2" onBlur="" value="t2">
</td>
</tr>
<tr>
<td>
<input type="text" name="t1" onClick="alert(this.parentElement.parentElement.all.t2.value)" value="t11">
</td>
<td>
<input type="text" name="t2" onBlur="" value="t22">
</td>
</tr>
<table>
llhdf 2004-11-24
  • 打赏
  • 举报
回复
请大家看看,请问怎么实现这样得功能。
llhdf 2004-11-23
  • 打赏
  • 举报
回复
请大家看看,请问怎么实现这样得功能。
llhdf 2004-11-23
  • 打赏
  • 举报
回复
怎么不行啊!
<BODY>
<table id="tab1" border="1">
<tr>
<td><input type="text" name="t1" onClick="alert(t1.nextSibling.value)" value="t1"></td>
<td><input type="text" name="t2" onBlur="" value="t2"></td>
</tr>
</table>
<BODY>

要是有表格怎么办?,请高手看看,怎么处理这样得情况,要是在一个页面中有多个t1,
但是我希望在某一节点下面,例如在节点t1处,我想获得t2对象元素,请问怎么实现?
<BODY>
<table id="tab1" border="1">
<tr>
<td>
<input type="text" name="t1" onClick="alert('显示t2得value')" value="t1">
</td>
<td>
<input type="text" name="t2" onBlur="" value="t2">
</td>
</tr>
<table>
<table id="tab1" border="1">
<tr>
<td>
<input type="text" name="t1" onClick="alert('显示t2得value')" value="t11">
</td>
<td>
<input type="text" name="t2" onBlur="" value="t22">
</td>
</tr>
<table>
</BODY>
梅雪香 2004-11-23
  • 打赏
  • 举报
回复
nextSibling 获取对此对象的下一个兄弟对象的引用。

nextSibling Property Internet Development Index

--------------------------------------------------------------------------------

Retrieves a reference to the next child of the parent for the object.

What's New for Microsoft® Internet Explorer 6
This property now applies to the attribute object.

Syntax

HTML N/A
Scripting [ oElement = ] object.nextSibling

Possible Values

oElement Object that receives the next sibling.

The property is read-only. The property has no default value.

Example

This example uses the nextSibling property to obtain the next item in the list.

HideExample

<SCRIPT>
// returns the list item labeled 'List Item 2'
var oSibling = oList.childNodes(0).nextSibling;
</SCRIPT>
<BODY>
<UL ID = oList>
<LI>List Item 1
<LI>List Item 2
<LI>List Item 3
</UL>
<BODY>



previousSibling 获取对此对象的上一个兄弟对象的引用。
previousSibling Property Internet Development Index

--------------------------------------------------------------------------------

Retrieves a reference to the previous child of the parent for the object.

What's New for Microsoft® Internet Explorer 6
This property now applies to the attribute object.

Syntax

HTML N/A
Scripting [ oElement = ] object.previousSibling

Possible Values

oElement Object that receives a reference to the previous sibling of an object.

The property is read-only. The property has no default value.

Example

This example uses the previousSibling property to obtain the previous sibling of a list item.

HideExample

<SCRIPT>
// returns the list item labeled 'List Item 1'
var oSibling = oList.childNodes(1).previousSibling;
</SCRIPT>
:
<BODY>
<UL ID = oList>
<LI>List Item 1
<LI>List Item 2
<LI>List Item 3
</UL>
</BODY>
Standards Information

This property is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 .
DARKNESSFALL 2004-11-23
  • 打赏
  • 举报
回复
楼上已经解决了
kchen2001 2004-11-23
  • 打赏
  • 举报
回复
同问:<td><input type="text" value=""><span></span></td>
这里的This代表控件input,那么后面的span怎么通过this指定?
ttyp 2004-11-23
  • 打赏
  • 举报
回复
<input type="text" name="t1" value="" onClick="alert(document.all.t2.value)">
u2g2000 2004-11-23
  • 打赏
  • 举报
回复
t1.nextSibling

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧