Jquery

jquery checkbox
  • 조회수 16,913
  • 작성일 2010-10-24
  •  

1. 개수 구하기
$("input[name=chk]:checkbox:checked").length
$("input[name='chk[]']:checked").length

2. 체크 확인
$("#check_all").is(':checked')

3. chk 개수만큼 돌면서 실행
$("input[name=chk]").each(
  function(){
    // 명령어
  }
)

4. each 실행되면서 그 값이 참이면 실행하는 로직
var chk2 = $("input[name='chk2[]']");
var i = 0;
$("input[name='chk1[]']").each(
  function(){
    if(this.checked){
      chk2[i].value = "Y";
    }else{
      chk2[i].value = "N";
    }
    i++;
  }
);

5. 전체선택/전체해제
if($('#checkbox').is(':checked')){
  $('.listCheck').each(function(){
    if($(this).is(':checked')){
      $(this).attr('checked','');
    }else{
      $(this).attr('checked','checked');
    }
  });
}else{
  $('.listCheck').each(function(){
    $(this).attr('checked','');
  });
}


  • Comment 2013-08-13 17:40
if($('#xzb7:checked').length) {
    var data7 = "J";
  } else {
    var data7 = "K";
  }
  • Comment 2020-02-02 21:37
var chknum = 0;
var chknum = $("input[name='eKind[]']:checkbox:checked").length;
if (chknum == 0)
{
  alert('진료과목은 한개이상 선택하여 주세요.');
  return false;
}