判断复选框是否被选中

时间:2021-06-22 09:00:50

function  checkValue()  {     var input_list = document.getElementsByTagName("input");  for (i=0; i< input_list.length; i ++) {  thisInput = input_list[i];  if(thisInput.type.toLowerCase()=="checkbox"){   if(getCheckedValue(document.getElementsByName(thisInput.name)) == ""){    thisInput.focus();    window.scrollBy(0, -30);    alert("该项不能为空!");    return false;   }  } }   return true;}

 

function getCheckedValue(radioObj) { if(!radioObj)  return ""; var radioLength = radioObj.length; if(radioLength == undefined) if(radioObj.checked)  return radioObj.value; else  return ""; for(var i = 0; i < radioLength; i++ ) {  if(radioObj[i].checked){   return radioObj[i].value;  } } return "";}