Usage:
Cascade (checkbox name)
Select All checkbox IDS as name0
The id of the sub-checkbox is name0 [[Parent id _] [Parent id _]...] id
Cascade = function (checkboxName ){
$ (": Checkbox [name = '" + checkboxName + "']"). click (function (){
CascadeCheck (this. id );
});
};
CascadeCheck = function (nElementID ){
Var isChecked = $ ('#' + nElementID). attr ('checked ');
Var sParentId = nElementID. substr (0, nElementID. lastIndexOf ('_'); // parent node
$ (": Checkbox [id ^ = '" + nElementID + "_']"). attr ('checked', isChecked); // select all child nodes
If (ischecked ){
Bchecked = true;
$ (": Checkbox [name = '" + $ (' # '+ nelementid). ATTR ('name') + "']"). Filter (function (){
Return nelementid. indexof (this. ID + '_') === 0;
}). ATTR ('checked', true); // traverse the sibling Node
} Else {
Bchecked = $ (": checkbox [ID ^ = '" + sparentid + "_']"). Filter (function (){
Return this. id. substring (sParentId. length + 1). indexOf ('_') ===- 1 & this. checked === true;
}). Length! = 0; // traverse to the root node
}
If (! IsChecked &&! BChecked & sParentId! = ''){
$ ('#' + SParentId). attr ('checked', false );
CascadeCheck (sParentId );
}
}
Source: http://Jorkin.Reallydo.Com/default.asp? Id = 566