Searchlabels:
for (var i=0; i<arrlabels.length; 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 ';
Inputelementtype = Inputelement.getattributenode (' type '). Value;
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 isn't hidden but belongs to a group of hidden radios it would still work.
Arrlabels[i].onclick = Crir.toggleradiolabel;
Inputelement.onclick = Crir.toggleradiolabel;
}
}
},
Uncheck (Label class) all radios in the same group
for (var i=0; i<arrinputs.length; 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 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.