JQuery
[JQuery] input type checkbox class 클래스로 접근 / 체크박스 개수 구하기 / 선택된 체크박스 개수 구하기
chsr
2021. 2. 18. 09:59
728x90
반응형
■ JQuery input type checkbox class 클래스로 접근 / 선택된 체크박스 개수 구하기
■ 사용법
# 예제 1 ( 클래스명 tmpChkbox 를 가진 모든 체크박스 개수 구하기 )
<input type='checkbox' class='tmpChkbox' name='tmpChkbox[]' value='A' checked>
<input type='checkbox' class='tmpChkbox' name='tmpChkbox[]' value='B' checked>
<input type='checkbox' class='tmpChkbox' name='tmpChkbox[]' value='C'>
<script type="text/javascript">
$(document).ready(function() {
var tmpChkCnt = $(".tmpChkbox").length;
console.log(tmpChkCnt); // 3 (A,B,C)
});
</script>
# 예제 2 ( 클래스명 tmpChkbox 를 가진 체크박스 중 선택된 체크박스 개수 구하기 )
<input type='checkbox' class='tmpChkbox' name='tmpChkbox[]' value='A' checked>
<input type='checkbox' class='tmpChkbox' name='tmpChkbox[]' value='B' checked>
<input type='checkbox' class='tmpChkbox' name='tmpChkbox[]' value='C'>
<script type="text/javascript">
$(document).ready(function() {
var tmpChkCnt = $(".tmpChkbox:checked").length;
console.log(tmpChkCnt); // 2 (A,B)
});
</script>
728x90
반응형