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','');
});
}
이전글 | jquery Cycle Plugin |
---|---|
다음글 | Ajax 활용 (1) |