当前位置: 代码迷 >> Web前端 >> 关于checkbox处置
  详细解决方案

关于checkbox处置

热度:309   发布时间:2012-06-29 15:48:47.0
关于checkbox处理
<!-- Created by TopStyle Trial - www.topstyle4.com -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
<script type="text/javascript">

function checkAll(input1,input2){

  var allcheck =   document.forms[input1];
  var str='';
  var lengthall = allcheck.length;
  for(var count=0; count < lengthall ; count++){
       if(input2.checked == true){
       if(allcheck.elements[count].type == "checkbox"){
       allcheck.elements[count].checked= true;
       if(str != ''){
       str += allcheck.elements[count].value+",";
       }else{
       str= allcheck.elements[count].value+","
       }
        
       }
       }else{
       if(allcheck.elements[count].type == "checkbox"){
       allcheck.elements[count].checked= false;
       }
       }
  }
  alert(str);
}


</script>
<body>
<input type="checkbox" onclick="checkAll('testForm',this)">
   <form id="testForm" name="testForm">
      <input type="checkbox" value="1">
      <input type="checkbox" value="2">
      <input type="checkbox" value="3">
      <input type="checkbox" value="4">
      <input type="checkbox" value="5">
   </form>
</body>
</html>
  相关解决方案