Use the Jquery selector to calculate the total of a row in a column in the table.
The Jquery selector is used to calculate a column in a table. It is very convenient to calculate the total of a row. The following uses the calculated row sum as an example:
Core algorithms:
$('#tableId tr').each(function() { $(this).find('td:eq(columnIndex)').each(function() { totalAmount += parseFloat($(this).text());})});
The following is the case code.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
:
Use jquery to get the data of a row in the selected table ,?
<Table>
<Tr> <td> Row 1 column 1 </td> <td> Row 1 column 2 </td> <td> Row 1 column 3 </td> </tr>
<Tr> <td> Row 2 column 1 </td> <td> Row 2 column 2 </td> <td> Row 2 column 3 </td> </tr>
</Table>
<Script type = "text/javascript">
Function getRow (rowIndex ){
Return $ ("table tr"). eq (rowIndex );
}
Function getCell (rowIndex, cellIndex ){
Return $ ("table tr"). eq (rowIndex). find ("td"). eq (cellIndex );
}
</Script>
How does JQuery obtain the values of a column in a row of a dynamic table?
Well... According to the LZ code, I do not quite understand the output effect,
But I modified some of the source code and tried a method. LZ, you can check it out.
Var shtml = '';
For (var I = 1; I <3; I ++ ){
Var item = 'testing ';
Shtml + = '<tr name = "result" id = "tr [' + I + ']"> ';
Shtml + = '<td id = "td1" height = "25" align = "left" valign = "middle">' + item. inclutive_date + '</td> ';
Shtml + = '<td id = "td7" height = "25" align = "left" valign = "middle"> <a href = "#" onclick = "">' + item. PJPTARGET_TOWNCOUNT_DAY + '</a> </td> ';
Shtml + = '<td id = "td8" height = "25" align = "left" valign = "middle"> <a href = "#" onclick = "">' + item. PJPACTUAL_TOWNCOUNT_DAY + '</a> </td> ';
Shtml + = '<td id = "td9" height = "25" align = "left" valign = "middle">' + item. ACTTOWNNUM + '</td> ';
Shtml + = '<td id = "td10" height = "25" align = "left" valign = "middle">' + item. TOWNPJP_PERCENT + '</td> ';
Shtml + = '<td id = "td11" height = "25" align = "left" valign = "middle">' + item. FARDISTANCE_BYDT + '</td> ';
Shtml + = '<td id = "td12" height = "2 ...... the remaining full text>