Copy codeThe Code is as follows:
<! -- Children object array element example -->
<Html>
<Body>
<Table id = "tbl">
<Tbody> <tr> <td> Row 1 column 1 </td> <td> Row 1 column 2 </td> </tr>
<Tr> <td> Row 2 column 1 </td> <td> Row 2 column 2 </td> </tr>
</Tbody>
</Table>
<Input onclick = "alert (document. all. tbl. children (0). children (0). innerHTML)" value = "children (0)" type = "button">
<Input onclick = "alert (document. all. tbl. children (0). children (1). innerHTML)" value = "children (1)" type = "button">
<Input onclick = "alert (document. all. tbl. children (0 ). children (1 ). children (0 ). innerHTML) "value =" children (2) "type =" button ">
<Div id = test>
<A> </a>
<Table> </table>
</Div>
<Script>
Alert (test. children [0]. tagName)
Alert (test. children [1]. tagName)
</Script>
</Body>
</Html>
<! -- In DOM, the elements on the entire page are tree structures.
Children represents the child node array of the object -->
Document. all. tbl. children (0). children (0). Explanation of innerHTML
Document. all. tbl. children (0) locate the first subnode of the table <tbody>
Document. all. tbl. children (0 ). children (0) locates the first subnode of the first subnode of the table <tr>, print the result <td> Row 1 column 1 </td> <td> Row 1 column 2 </td>
Document. all. tbl. children (0 ). children (1 ). innerHTML, print the result <td> Row 2 column 1 </td> <td> Row 2 column 2 </td>
Document. all. tbl. children (0). children (1). children (0). innerHTML prints the result row, 2 columns, and 2 columns.
<! -- FistChild, lastChild example -->
<Html>
<Body>
<Table id = "tbl">
<Tbody> <tr id = "tr1"> <td> Row 1 column 1 </td> <td> Row 1 column 2 </td> </tr>
<Tr> <td = "tr2"> Row 2 column 1 </td> <td> Row 2 column 2 </td> </tr>
</Tbody>
</Table>
<Input onclick = "alert (document. all. tbl. firstChild. firstChild. innerHTML)" value = "children (0)" type = "button">
<Input onclick = "alert (document. all. tbl. firstChild. lastChild. innerHTML)" value = "children (1)" type = "button">
<Input onclick = "alert (document. all. tbl. firstChild. lastChild. firstChild. innerHTML)" value = "children (2)" type = "button">
<Div id = test>
<A> </a>
<Table> </table>
</Div>
<Script>
Alert (test. firstChild. tagName)
Alert (test. lastChild. tagName)
</Script>
</Body>
</Html>
Document. all. tbl. firstChild: locate the first subnode of the table <tbody>
Document. all. tbl. firstChild. firstChild: locate the first subnode of the table. <tbody>
<Tr id = "tr1">
Document. all. tbl. firstChild. firstChild. innerHTML: <td> Row 1 column 1 </td> <td> Row 1 column 2 </td>
Document. all. tbl. firstChild. lastChild: locate the first subnode of the table. <tbody>
<Tr id = "tr2">
Document. all. tbl. firstChild. lastChild. innerHTML: <td = "tr2"> Row 2 column 1 </td> <td> Row 2 column 2 </td>
Document. all. tbl. firstChild. lastChild. firstChild. innerHTML:
Row 2 column 2