Example of selecting rows and columns using jquery

Source: Internet
Author: User

Jquery Method
Copy codeThe Code is as follows:
$ (
Function (){

// Calculate the total value of the personnel statistical table during page loading
CalcSum ();

});

// Calculates the total number of rows.
/*
Aggregate behavior intermediate Variables
Add each cell to the total row of the column
Obtain the total number of columns.
*/
Function trVisible (chk, index ){

Var disValue = $ ("# Tr" + index.html .css ("display ");
If (chk. checked ){

$ ("# Tr" + index.html .css ("display", "block ");
}
Else {
$ ("# Tr" + index.html .css ("display", "none ");
}
CalcSum ();
}
Function calcSum (){

// The total row has an initial value of 0.
$ ("# TrSum"). each (function (){
$ (This). find ("td"). each (function (){
If ($ (this). index ()! = 0 ){
$ (This). text ("0 ");
}
});
});

$ ("# Tabrytj"). find ("tr"). each (function (){
Var trDis = require (this).css ("display ");
// Hide rows not involved in Calculation
If (trDis = "block "){
$ (This). find ("td"). each (function (){
Var index = $ (this). index ();
If (index> = 1 ){
Var tdValue = $ ("# trSum"). find ("td: eq (" + index + ")"). text ();
// TotalSum + = parseFloat ($ (this). text ());
$ ("# TrSum "). find ("td: eq (" + index + ")"). text (parseFloat (tdValue) + parseFloat ($ (this ). text ()));
}
});
}
});


}

Html statement
Copy codeThe Code is as follows:
<Table>
<Tr>
<Td> branch </td>
<Td>
<Select>
<Option>
China South Branch
</Option>
</Select>
</Td>
<Td> <input type = "checkbox" onclick = "trVisible (this, 1) "name =" chk1 "id =" chk1 "checked =" checked "/> 1 </td>
<Td> <input type = "checkbox" onclick = "trVisible (this, 2)" checked = "checked"/> 2 </td>
<Td> <input type = "checkbox" onclick = "trVisible (this, 3)" checked = "checked"/> 3 </td>
<Td> <input type = "checkbox" onclick = "trVisible (this, 4)" checked = "checked"/> figure 4 </td>
<Td> <input type = "checkbox" onclick = "trVisible (this, 5)" checked = "checked"/> 5 </td>
<Td> <input type = "checkbox" onclick = "trVisible (this, 6)" checked = "checked"/> 6 </td>
</Tr>
</Table>



<Div>
<Table border = "0" class = "tableinfo" id = "tabrytj">
<Tr id = "Tr1" style = "display: block">
<Td> 1 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
</Tr>
<Tr id = "Tr2" style = "display: block">
<Td> 2 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
</Tr>
<Tr id = "Tr3" style = "display: block">
<Td> Zhang 23 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
<Td> 124536 </td>
</Tr>
<Tr id = "trSum">
<Td> </td>
<Td> 0 </td>
<Td> 0 </td>
<Td> 0 </td>
<Td> 0 </td>
<Td> 0 </td>
<Td> 0 </td>
<Td> 0 </td>
<Td> 0 </td>
<Td> 0 </td>
<Td> 0 </td>
</Tr>
</Table>
</Div>

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.