728x90

<form name='my_form'>
  <input type='button' id='my_button' value='개수 카운트' />
  <hr>
  <input type='text' name='tag' class='chk0' value='1' />
  <input type='text' name='tag' class='chk0' value='2' />
  <input type='text' name='tag' class='chk0' value='3' />
  <input type='text' name='tag' class='chk0' value='' />
  <input type='text' name='tag' class='chk0' value='' />
</form>

<script src="//code.jquery.com/jquery.min.js"></script>
<script>
$("#my_button").click(function() {
    //alert($("input[class='chk0']").length); // 전체 개수
    var count = 0;
    $('.chk0').filter(function() {
        if(this.value.trim().length > 0){ // 체크한 것의 개수
            count++;
        }
    });
    alert(count);

});
</script>

'Web 프로그램 > js, jQuery' 카테고리의 다른 글

jQuery map 함수  (0) 2018.04.29
Javascript 배열 정리  (0) 2018.04.29
jQuery 체크박스 선택 여부 확인  (0) 2018.04.15
Popup Modal with jQuery  (0) 2018.04.12
jQuery animate  (2) 2018.02.14
블로그 이미지

Link2Me

,