<table id= "tb1" width= "border=" 1 "cellpadding=" 4 "cellspacing=" 0 ">
<tr> <td height=
" 25 " > First line </td>
</tr>
<tr>
<td height= "A" > second line </td>
</tr> <tr>
<td height= > Third line </td>
</tr>
<tr>
<td height= ">" Line four </td>
</tr>
<tr>
<td height= "><input type=" button "Name=" Gettablecontent "value=" Get Table Contents "onclick=" gettablecontent (this) ></td>
</tr>
</table >
As shown in the Code, the button clicks the event to pass in the This object, which is the button itself. Test the data that gets the table in the following ways
<script language= The parent node
of the parent node of the JavaScript > Function gettablecontent (node) {
//button is tr.
var tr1 = Node.parentNode.parentNode;
alert (tr1.rowindex);
alert (Tr1.cells[0].childnodes[0].value); Method of obtaining one
alert (tr1.cells[0].innertext);
Find the Table object in the following ways, getting tr,td. Then get TD's HTML content
var table = document.getElementById ("tb1");//Get first table
var child = Table.getelementsbytagname (" TR ") [rowindex-1];//gets the first cell of the row
var text = Child.firstChild.innerHTML;
Window.alert ("form" + RowIndex + "content is:" + text);
}
</script>
The above is small series for everyone to get the table node of the TR and TD content simple examples of all the content, I hope we support cloud Habitat Community ~