1. Hide a specified column in a specified table
[Javascript]
$ (": Checkbox [name * = month]"). each (function (){
If (! $ (This). attr ("checked ")){
Var colnum = $ (this). val ();
$ ("# ListPage"). find ('tr '). find ("td: eq (" + colnum. toString () + ")"). hide ();
$ ("# ListPage"). find ('tr '). find ("th: eq (" + colnum. toString () + ")"). hide ();
} Else {
Var colnum = $ (this). val ();
$ ("# ListPage"). find ('tr '). find ("td: eq (" + colnum. toString () + ")"). show ();
$ ("# ListPage"). find ('tr '). find ("th: eq (" + colnum. toString () + ")"). show ();
}
});
$ (": Checkbox [name * = month]"). each (function (){
If (! $ (This). attr ("checked ")){
Var colnum = $ (this). val ();
$ ("# ListPage"). find ('tr '). find ("td: eq (" + colnum. toString () + ")"). hide ();
$ ("# ListPage"). find ('tr '). find ("th: eq (" + colnum. toString () + ")"). hide ();
} Else {
Var colnum = $ (this). val ();
$ ("# ListPage"). find ('tr '). find ("td: eq (" + colnum. toString () + ")"). show ();
$ ("# ListPage"). find ('tr '). find ("th: eq (" + colnum. toString () + ")"). show ();
}
});
Or:
[Javascript]
$ (Document). ready (function (){
$ ("Td: eq (2)", $ ("tr"). hide ();
$ ("Td: eq (3)", $ ("tr"). hide ();
$ ("Td: eq (4)", $ ("tr"). hide ();
$ ("# Button1"). click (function (){
$ ("Td: eq (2)", $ ("tr ")). toggle (1000); // if it is set to 0, no animation is required. 1000 is displayed or hidden in 1 second.
$ ("Td: eq (3)", $ ("tr"). toggle (1000 );
$ ("Td: eq (4)", $ ("tr"). toggle (1000 );
});
});
$ (Document). ready (function (){
$ ("Td: eq (2)", $ ("tr"). hide ();
$ ("Td: eq (3)", $ ("tr"). hide ();
$ ("Td: eq (4)", $ ("tr"). hide ();
$ ("# Button1"). click (function (){
$ ("Td: eq (2)", $ ("tr ")). toggle (1000); // if it is set to 0, no animation is required. 1000 is displayed or hidden in 1 second.
$ ("Td: eq (3)", $ ("tr"). toggle (1000 );
$ ("Td: eq (4)", $ ("tr"). toggle (1000 );
});
});
2. Get the number of columns in the table
[Javascript]
Var col = $ ("# listPage"). find ("th"). prevAll (). length; // obtain the number of table columns
For (var I = 0; I <= col; I ++ ){
If ($ ("# listPage "). find ('tr '). find ("th: eq (" + I. toString () + ")" detail .css ("display") = 'None') {// determines whether the column is hidden.
$ ("Input [value =" + I + "]"). attr ("checked", false );
} Else {
$ ("Input [value =" + I + "]"). attr ("checked", true );
}
}
Var col = $ ("# listPage"). find ("th"). prevAll (). length; // obtain the number of table columns
For (var I = 0; I <= col; I ++ ){
If ($ ("# listPage "). find ('tr '). find ("th: eq (" + I. toString () + ")" detail .css ("display") = 'None') {// determines whether the column is hidden.
$ ("Input [value =" + I + "]"). attr ("checked", false );
} Else {
$ ("Input [value =" + I + "]"). attr ("checked", true );
}
}
3. In jquery, if you want to find a visible element, use: visible.
For example, $ ("tr: visible ")
You can use
$ ("Tr: not (': visible.