This article mainly introduces how jquery implements the example of select selected rows and column total. For more information, see the Jquery method.
The 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
The Code is as follows:
Branch |
China South Branch
|
Sheet 1 |
Zhang 2 |
Zhang 3 |
Figure 4 |
Sheet 5 |
Zhang 6 |
Sheet 1 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
Zhang 2 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
Zhang 23 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
124536 |
|
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |