父类 复制代码 代码如下: 子类 复制代码 代码如下: 实现代码 复制代码 代码如下: <BR>function CheckboxGroup(){ <BR>var arrelement = document.all; <BR>var i=0; <BR>while(i<arrelement.length){ <BR>var forgroupattrib = arrelement[i].getAttribute('forcheckboxgroup'); <BR>if(forgroupattrib != null && forgroupattrib != ''){ <BR>arrelement[i].setAttribute('groupmember',_getGroupMember(arrelement[i])); <BR>if(arrelement[i].tagName.toLowerCase() == 'input' && arrelement[i].type == 'checkbox'){ <BR>arrelement[i].onclick=function(){ <BR>//----------------------Checked All------------------ <BR>var groupmember = this.getAttribute('groupmember'); <BR>var i = 0; <BR>while(i<groupmember.length){ <BR>groupmember[i].checked = this.checked; <BR>i++; <BR>} <BR>//--------------------------------------------------- <BR>} <BR>} <BR>_setState(arrelement[i]); <BR>} <BR>i++; <BR>} <BR>} <br><br>function _getGroupMember(o){ <BR>var groupname = o.getAttribute('forcheckboxgroup'); <BR>var items = new Array; <BR>var inputs = document.getElementsByTagName('input'); <BR>var i=0; <BR>while(i<inputs.length){ <BR>if(inputs[i].type == 'checkbox'){ <BR>var groupattrib = inputs[i].getAttribute('group'); <BR>if(groupattrib == groupname){ <BR>items[items.length] = inputs[i]; <BR>var master = inputs[i].getAttribute('groupmaster'); <BR>if (master == null) { <BR>master = new Array; <BR>master[0] = o.uniqueID; <BR>inputs[i].setAttribute('groupmaster', master); <BR>} <BR>else{ <BR>master[master.length] = o.uniqueID; <BR>} <BR>inputs[i].onpropertychange = function(){ <BR>if (event.propertyName == 'checked') { <BR>var arro = this.getAttribute('groupmaster'); <BR>var i = 0; <BR>while (i < arro.length) { <BR>_setState(document.getElementById(arro[i])); <BR>i++; <BR>} <BR>} <BR>} <BR>} <BR>} <BR>i++; <BR>} <BR>return items; <BR>} <br><br>function _setState(o){ <BR>var master = o; <BR>if(master!=null){ <BR>var chkselall = true; <BR>var chknosel = true; <BR>var groupmember = master.getAttribute('groupmember'); <BR>var i = 0; <BR>while(i<groupmember.length){ <BR>if(chkselall)chkselall = groupmember[i].checked; <BR>if(chknosel)chknosel = !groupmember[i].checked; <BR>i++; <BR>} <BR>if(master.tagName.toLowerCase() == 'input'&&master.type=='checkbox'){ <BR>if (chkselall) { <BR>master.indeterminate = false; <BR>master.checked = true; <BR>} <BR>if (chknosel) { <BR>master.indeterminate = false; <BR>master.checked = false; <BR>} <BR>if(!chkselall&&!chknosel)master.indeterminate = true; <BR>} <BR>else{ <BR>master.disabled = chknosel; <BR>} <BR>} <BR>} <br><br>window.attachEvent('onload',CheckboxGroup); <BR>