NOTICE

전체 선택, 해제

Date : 2008. 11. 9. 12:00 Category : Programming/Javascript
<script>
function checkAll(Obj) {
   var chkBox = document.getElementsByName("num[]");

   for(i=0; i<chkBox.length; i++) {
      if(chkBox[i] != undefined) {
         var chkLen = chkBox[i].length;

         if(!chkLen) {
            chkBox[i].checked = Obj.checked;
         } else {
            for(i = 0; i < chkLen; i++) {
               chkBox[i].checked = Obj.checked;
            }
         }
      }
   }
}
</script>
<input type="checkbox" onclick="checkAll(this)"><br />
<input type="checkbox" name="num[]" /><br />
<input type="checkbox" name="num[]" /><br />
<input type="checkbox" name="num[]" /><br />
<input type="checkbox" name="num[]" />

[test]
전체 선택
1
2
3
4
[/test]