체크 박스를 체크/체크하지 않으려 고 모든 체크 박스를 체크/체크하지 않으려 고합니다.두 개의 다른 클래스로 모든 체크 박스를 확인하는 방법
HTML :
<th><input type="checkbox" name="pay" id="chkAll" class="chkAll"/>With Pay</th>
<th><input type="checkbox" name="pay" id="chkAll2" class="chkAll2"/>Without Pay</th>
<td><input type="checkbox" name="pay" value="With Pay" class="chk" id="chk"/></td>
<td><input type="checkbox" name="pay" value="Without Pay" class="chk2" id="chk2"/></td>
JS : 여기
내 코드입니다$('.chkAll').change(function() {
var id = $(this).attr("id").replace("check_", "");
if ($(this).is(':checked')) {
$(".chk").prop('checked', true);
$(".chk2").prop('checked', false);
$('.chkAll2').prop('checked', false);
} else {
$(".chk").prop('checked', false);
}
});
$('.chkAll2').change(function() {
var id = $(this).attr("id").replace("check_", "");
if ($(this).is(':checked')) {
$(".chk2").prop('checked', true);
$(".chk").prop('checked', false);
$('.chkAll').prop('checked', false);
} else {
$(".chk2").prop('checked', false);
}
});
$('.chk').not('[id^=chkAll]').change(function() {
if ($(this).is(':checked')) {
$('.chkAll').prop('checked', true);
} else {
$('.chkAll').prop('checked', false);
}
});
다음에 대한 간단한 jQuery 코드
에게있다' 클래스 '라고합니다. –