메뉴 건너뛰기

?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

목록의 체크 선택/해제에 따라 [전체선택] 체크박스를 체크하거나 해제하기 


동적으로 생성된 목록에서
체크박스를 모두 선택하면 --> 목록 상단의 [전체선택/해제] 체크박스를 체크하고
체크박스를 하나라도 해제하면 --> 목록 상단의 [전체선택/해제] 체크박스를 체크해제
 

HTML 부분

아래의 HTML 코드 중 주석 부분을 jQuery로 동적 생성시 제어가 당초 생각했던 코드대로 실행되지 않았다
그래서 동적 생성 HTML일 경우 아래처럼 처리해 보았다
<table id="table-03" class="table table-responsive table-grtc-01 no-margin has-check" summary="사진정보 이력">
    <thead>
    <tr class="text-center-group vertical-middle-group">
        <th>
            <div class="checkbox">
                <input type="checkbox" value="" aria-label="check" title="check" class="cursor-pointer">
                <label></label>
            </div>
        </th>
        <th>촬영일자</th>
        <th>촬영기관</th>
        <th>사진설명</th>
    </tr>
    </thead>
    <tbody>
    <!--
    <tr class="vertical-middle-group">
        <td class="text-center-group">
            <div class="checkbox">
                <input type="checkbox" value="option1" aria-label="check" title="check" class="cursor-pointer">
                <label></label>
            </div>
        </td>
        <td class="text-center">2016/05/16</td>
        <td class="tooltip-demo txt-ellipsis-td">
            <span data-toggle="tooltip" data-placement="top" title="김해시">김해시</span>
        </td>
        <td class="tooltip-demo txt-ellipsis-td">
            <span data-toggle="tooltip" data-placement="top" title="20160415_sample.jpg">20160415_sample.jpg</span>
        </td>
    </tr> -->
    </tbody>
</table>
 

jQuery 부분

//$('input[name="tpiSeqs"]').click(function(){ //동적 생성된 HTML에서는 작동 안됨
$(document).on('click', 'input[name="tpiSeqs"]', function(){ //동적 생성된 HTML에서도 작동됨
    //var totLength = $(this).length; //이건 항상 1이 나왔음
    var totLength = $('input[name="tpiSeqs"]').length; //이건 예상했던 개수가 나옴
    var chkLength = $('input[name="tpiSeqs"]:checked').length;

    if (totLength > 0 && totLength == chkLength) {
        console.log("on:");
        $('#table-03 thead input:checkbox').prop("checked",true);
    } else {
        console.log("off");
        $('#table-03 thead input:checkbox').prop("checked",false);
    }
});


List of Articles
번호 제목 날짜 조회 수
159 hover 메소드를 이용해서 메뉴 on, off를 구현 file 2016.09.21 8476
158 화면 이동시에 레이어가 따라다니게 하기 2016.09.21 7141
157 다른 프레임에 있는 객채 참조하는 방법 2016.09.21 6471
156 동적으로 콤보(select)의 항목(option) 생성하기 2016.09.21 14374
155 FORM 객체 초기화 하기 2016.09.21 7346
154 jQuery 예약어 $ 를 사용하지 못하는 경우 해결책 noConflict() 2016.09.21 6679
153 POST 방식으로 인수를 전달하고 그 결과를 받아오기 2016.09.21 9202
152 키보드 이벤트가 발생한 객체의 id값 알아내기 2016.09.21 7530
151 getScript() 2016.09.21 7125
150 속성선택자를 이용해서 링크에 스타일 입히기 2016.09.21 11535
149 getJSON() 함수 2016.09.21 8379
148 load() 메소드 2016.09.21 6412
147 zeroclipboard - 클립보드 복사하기(자바스크립트 클립보드 복사하기) 2016.10.06 7181
146 jquery 디데이 계산 (D-day,Dday) file 2016.11.17 8801
145 jquery 라디오버튼 선택 확인, 체크박스 선택 확인, 셀렉트박스 선택 확인 2016.11.17 7149
144 jquery 글자 byte, 문자열 byte(바이트) 길이 체크하기 예제 2016.11.17 8836
143 Html 색상표 모음, 색상코드표 (RGB), 이미지X, 복사 가능 file 2016.11.17 8145
142 Table을 DIV로 표현하기 (예제) file 2016.11.17 7468
141 jquery enter key event submit (jquery 엔터키 이벤트) 2016.11.17 6857
140 jQuery, JavaScript 새로고침(reload) 2016.11.17 6951
Board Pagination Prev 1 2 3 4 5 6 7 8 9 Next
/ 9

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved