javascript子級對象獲得父級對象屬性
parentElement 父
parentNode 父
childNodes[] 子
nextSibling 兄弟
previousSibling
例子:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www./TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>111</title> </head> <body> <table id="t1" border=1>
<tr id="tr">
<td id="t2">第一個單元格
<a href="#" onClick="alert
(this.parentNode.parentNode.parentNode.parentNode.id+this.parentNode.nextSibling.id)">點一下這個連接,提示表格的ID,第一個單元格的ID和二個單元格的ID???</a>
</td>
<td id="t3">第二個單元格</td>
</tr>
</table>
</body> </html>
|
document.getElementById( "table1 ").rows[i].cells[0].childNodes[0]
childNodes[0]為td標簽內(nèi)的對象
|