SearchLabels:
For (var I = 0; I // get the input element based on the for attribute of the label tag
If (arrLabels [I]. getAttributeNode ('for') & arrLabels [I]. getAttributeNode ('for '). value! = ''){
LabelElementFor = arrLabels [I]. getAttributeNode ('for'). value;
InputElement = document. getElementById (labelElementFor );
}
Else {
Continue searchLabels;
}
InputElementClass = inputElement. className;
// If the input is specified to be hidden intiate it
If (inputElementClass = 'crirhiddenjs '){
InputElement. className = 'crirhidden ';
// Add the appropriate event listener to the input element
If (inputElementType = "checkbox "){
InputElement. onclick = crir. toggleCheckboxLabel;
}
Else {
InputElement. onclick = crir. toggleRadioLabel;
}
// Set the initial label state
If (inputElement. checked ){
If (inputElementType = 'checkbox') {arrLabels [I]. className = 'checkbox _ checked '}
Else {arrLabels [I]. className = 'Radio _ checked '}
}
Else {
If (inputElementType = 'checkbox') {arrLabels [I]. className = 'checkbox _ unchecked '}
Else {arrLabels [I]. className = 'Radio _ unchecked '}
}
}
Else if (inputElement. nodeName! = 'Select' & inputElement. getAttributeNode ('type '). value = 'Radio ') {// this so even if a radio is not hidden but belongs to a group of hidden radios it will still work.
ArrLabels [I]. onclick = crir. toggleRadioLabel;
InputElement. onclick = crir. toggleRadioLabel;
}
}
},
FindLabel: function (inputElementID ){
ArrLabels = document. getElementsByTagName ('label ');
SearchLoop:
For (var I = 0; I if (arrLabels [I]. getAttributeNode ('for') & arrLabels [I]. getAttributeNode (''). value = inputElementID ){
Return arrLabels [I];
Break searchLoop;
}
}
},
ToggleCheckboxLabel: function (){
LabelElement = crir. findLabel (this. getAttributeNode ('id'). value );
// Uncheck (label class) all radios in the same group
For (var I = 0; I inputElementType = arrInputs [I]. getAttributeNode ('type'). value;
If (inputElementType = 'Radio '){
InputElementName = arrInputs [I]. getAttributeNode ('name'). value;
InputElementClass = arrInputs [I]. className;
// Find radio buttons with the same 'name' as the one we 've ve changed and have a class of chkHidden
// And then set them to unchecked
If (inputElementName = clickedInputElementName & inputElementClass = 'crirhidden '){
InputElementID = arrInputs [I]. getAttributeNode ('id'). value;
LabelElement = crir. findLabel (inputElementID );
LabelElement. className = 'Radio _ unchecked ';
}
}
}
// If the radio clicked is hidden set the label to checked
If (clickedInputElement. className = 'crirhidden '){
ClickedLabelElement. className = 'Radio _ checked ';
}
},
AddEvent: function (element, eventType, doFunction, useCapture ){
If (element. addEventListener)
{
Element. addEventListener (eventType, doFunction, useCapture );
Return true;
} Else if (element. attachEvent ){
Var r = element. attachEvent ('on' + eventType, doFunction );
Return r;
} Else {
Element ['on' + eventType] = doFunction;
}
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.