最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

javascript单选框,多选框美化代码_表单特效

来源:懂视网 责编:小采 时间:2020-11-27 20:39:40
文档

javascript单选框,多选框美化代码_表单特效

javascript单选框,多选框美化代码_表单特效:crir = { init: function() { arrLabels = document.getElementsByTagName('label'); 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]
推荐度:
导读javascript单选框,多选框美化代码_表单特效:crir = { init: function() { arrLabels = document.getElementsByTagName('label'); 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]

crir = {
init: function() {
arrLabels = document.getElementsByTagName('label');

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';

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 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('for').value == inputElementID) {
return arrLabels[i];
break searchLoop;
}
}
},

toggleCheckboxLabel: function () {
labelElement = crir.findLabel(this.getAttributeNode('id').value);

if(labelElement.className == 'checkbox_checked') {
labelElement.className = "checkbox_unchecked";
}
else {
labelElement.className = "checkbox_checked";
}
},

toggleRadioLabel: function () {
clickedLabelElement = crir.findLabel(this.getAttributeNode('id').value);

clickedInputElement = this;
clickedInputElementName = clickedInputElement.getAttributeNode('name').value;

arrInputs = document.getElementsByTagName('input');

// 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 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;
}
}
}

crir.addEvent(window, 'load', crir.init, false);

在线演示http://img.jb51.net/online/checkbox/sample.html

打包下载CRIR.rar

文档

javascript单选框,多选框美化代码_表单特效

javascript单选框,多选框美化代码_表单特效:crir = { init: function() { arrLabels = document.getElementsByTagName('label'); 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]
推荐度:
标签: 美化 特效 代码
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top