如何用JAVASCRIPT DOM,取得最后一td节点
<html>
<head>
<script type= "text/javascript " src= "tx.js "> </script>
</head>
<body>
<input type= "hidden " name= "jsp_name " value= "../proc.jsp ">
<table width= "98% " border= "0 " cellspacing= "0 " cellpadding= "0 ">
<tr>
<td height= "13 "> </td>
</tr>
<tr>
<td class= "td_title1 "> 职工基本信息表 </td>
</tr>
<tr>
<td height= "13 "> </td>
</tr>
<tr>
<td class= "td_title2 "> 增加职工基本信息 </td>
</tr>
<tr>
<td height= "13 "> </td>
</tr>
<tr>
<td height= "25 "> </td>
</tr>
<tr>
<td height= "25 " align= "center ">
<img src= "../img/queding.jpg " onClick= "sub_mit() ">
<img src= "../img/chongxie.jpg " onClick= "re_set() ">
</td>
</tr>
</table>
</body>
</html>
------解决方案--------------------t = document.getElementById( "tableid ")
alert(t.rows[t.rows.length-1].cells[t.rows[t.rows.length-1].cells.length-1].innerHTML)
------解决方案--------------------var tds = document.getElementsByTagName( "TD ");
var LastTd = tds[tds.length-1];
全文档的最后一个TD出来了
------解决方案-------------------- t = document.getElementsByTagName( "table ")[0]
alert(t.childNodes[0].childNodes.length);
bb.childNodes[0]是tbody
每个table都会自动生成一个tbody,tr是tbody下面的
<table>
<tbody>
<tr>
</tr>
</tbody>
</table>
------解决方案--------------------另外如果知道table元素,获取当前table的最后一个td也有很多方法
方法1:
var lastTd = tableElement.cells[tableElements.cells.length-1];
方法2:
var tds = tableElement.getElementsbyTagName( "TD ");
var lastTd = tds[tds.length-1];
这2种都是最简单的方法.