In actual development, the full-selection operation is often used. Here, a Jquery full-selection plug-in is written to facilitate the direct call of [javascript]/** jQuerylightweightpluginCheckAll * Originalauthor: Suifengshiqu * Furtherchanges, comm...
In actual development, all-selection operations are often used. Here, a Jquery all-selection plug-in is written to facilitate future direct calls.
[Javascript]
/*
* JQuery lightweight plugin CheckAll
* Original author: Suifengshiqu
* Further changes, comments: lvbo1988@gmail.com
*/
/* Select all INS in the table */
/* Usage */
/*
$ ("# Tab"). CheckAll ({valueField: "txtTest", chkId: "chkall", splitExp: "|", valueIndex: 0 });
*/
(Function ($ ){
$. Fn. extend ({
CheckAll: function (options ){
Var defaults = {
ValueField: null, // The default value field selected
ChkId: "c_all", // Id of the all-selected box
SplitExp: "_", // delimiter of the field
ValueIndex: 1 // index subscript of the split Value
};
Var options = $. extend (defaults, options );
Obj = $ (this); // The default value is table.
Function _ getSelectedValue (){
Var values = "";
$ ("#" + Obj. attr ("Id") + ": checked"). each (function (){
If ($ (this). attr ("id ")! = Options. chkId ){
Values + = $ (this). attr ("id"). split (options. splitExp) [options. valueIndex] + ",";
}
});
If (values. length> 0)
Return values. substring (0, values. length-1 );
Return values;
}
Return this. each (function (){
Var subExp = "#" + obj. attr ("Id") + ": checkbox ";
Var chks = $ (subExp + ": gt (0 )");
Var checkedCount = 0;
Chks. each (function (){
$ (This). click (function (){
If ($ (this). attr ("checked ")){
CheckedCount + = 1;
} Else {
CheckedCount-= 1;
}
If (checkedCount <chks. length ){
$ ("#" + Options. chkId). attr ("checked", false );
} Else {
$ ("#" + Options. chkId). attr ("checked", true );
}
$ ("#" + Options. valueField). val (_ getSelectedValue ());
});
});
$ ("#" + Options. chkId). click (function (){
$ (SubExp). attr ("checked", $ (this). attr ("checked ")? True: false );
If ($ (this). attr ("checked ")){
$ (SubExp). attr ("checked", true );
CheckedCount = $ (subExp + ": gt (0)"). length;
} Else {
$ (SubExp). attr ("checked", false );
CheckedCount = 0;
}
$ ("#" + Options. valueField). val (_ getSelectedValue ());
});
});
}
});
}) (JQuery );
The page call is as follows:
[Html]