数组 解析dom中的children对象数组元素firstChild,lastChild的使用
解析dom中的children对象数组元素firstChild,lastChild的使用
以下是对dom中的children对象数组元素firstChild lastChild的使用进行了详细的分析介绍 需要的朋友可以参考下 复制代码 代码如下:<! children对象数组元素示例 > <> <body> <table id="tbl"> <tbody> <tr> <td> 行 列 </td><td>行 列 </td></tr> <tr> <td> 行 列 </td><td>行 列 </td></tr> </tbody> </table> <input onclick="alert(document all tbl children( ) children( ) innerHTML)" value="children( )" type=button> <input onclick="alert(document all tbl children( ) children( ) innerHTML)" value="children( )" type=button> <input onclick="alert(document all tbl children( ) children( ) children( ) innerHTML)" value="children( )" type=button> <div id=test> <a></a> <table></table> </div> <script> alert(test children[ ] tagName) alert(test children[ ] tagName) </script> </body> </>
<! 在DOM中 整个页面里的元素是个树型结构 children 代表对象的子节点数组 >
document all tbl children( ) children( ) innerHTML解释 document all tbl children( )定位到table的第一个子节点<tbody> document all tbl children( ) children( ) 定位到table的第一个子节点的第一个子节点<tr> 打印结果<td> 行 列 </td><td>行 列 </td>
document all tbl children( ) children( ) innerHTML 打印结果<td> 行 列 </td><td>行 列 </td>
document all tbl children( ) children( ) children( ) innerHTML 打印结果行 列

<! fistChild lastChild示例 > <> <body> <table id="tbl"> <tbody> <tr id="tr "> <td> 行 列 </td><td>行 列 </td></tr> <tr> <td="tr "> 行 列 </td><td>行 列 </td></tr> </tbody> </table> <input onclick="alert(document all tbl firstChild firstChild innerHTML)" value="children( )" type=button> <input onclick="alert(document all tbl firstChild lastChild innerHTML)" value="children( )" type=button> <input onclick="alert(document all tbl firstChild lastChild firstChild innerHTML)" value="children( )" type=button> <div id=test> <a></a> <table></table> </div> <script> alert(test firstChild tagName) alert(test lastChild tagName) </script> </body> </>
document all tbl firstChild定位到table的第一个子节点<tbody> document all tbl firstChild firstChild定位到table的第一个子节点<tbody> 的第一个子节点<tr id="tr "> document all tbl firstChild firstChild innerHTML打印结果是<td> 行 列 </td><td>行 列 </td>
document all tbl firstChild lastChild定位到table的第一个子节点<tbody> 的最后子节点<tr id="tr "> document all tbl firstChild lastChild innerHTML打印结果是<td="tr "> 行 列 </td><td>行 列 </td>
lishixinzhi/Article/program/Java/JSP/201311/20059