Use the Jquery selector to calculate the total of a row in a column in the table.

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.