메뉴 건너뛰기

?

단축키

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);
    }
});


  1. foreach문

    Date2021.03.26 Views195
    Read More
  2. 항상 최신버전으로 사용하기

    Date2021.03.26 Views284
    Read More
  3. selectbox multiple 선택한 값들 submit 해서 받기

    Date2021.03.26 Views1364
    Read More
  4. DateTimepicker ( Timepicker + Datepicker )

    Date2021.03.26 Views787
    Read More
  5. 라디오 버튼 선택값 가져오기

    Date2021.03.26 Views229
    Read More
  6. 간단한 스크롤 따라 움직이는 메뉴 만들기

    Date2021.03.26 Views725
    Read More
  7. datepicker, onclick 이벤트시에 한번에 뜨게 하기

    Date2021.03.26 Views1453
    Read More
  8. Cesium에서 canvas 화면 center 지점의 좌표 취득

    Date2021.03.25 Views368
    Read More
  9. 모달 띄우는 코드

    Date2021.03.25 Views657
    Read More
  10. javascript, jQuery에서 루프 돌리기 예 (for, forEach, each)

    Date2021.03.25 Views276
    Read More
  11. jQuery 사용자 정의 속성이 잘 반영되지 않은 경우

    Date2021.03.25 Views158
    Read More
  12. 최초 접속시 css와 script가 로딩되지 않을때

    Date2021.03.25 Views322
    Read More
  13. ajax 동기화 처리하기

    Date2021.03.25 Views416
    Read More
  14. CSS로 요소에 대한 클릭 등 이벤트 발생을 막고 싶을 때

    Date2021.03.25 Views198
    Read More
  15. 목록의 체크 선택/해제에 따라 [전체선택] 체크박스를 체크하거나 해제하기

    Date2021.03.25 Views329
    Read More
  16. Ajax를 통해 전송된 데이터를 Controller에서 List 객체로 받기

    Date2021.03.25 Views12227
    Read More
  17. radio 제어하기

    Date2021.03.25 Views170
    Read More
  18. 모든 링크를 읽어들여 기존의 태그 뒤에 새창열기 태그를 추가하기 예

    Date2021.03.25 Views183
    Read More
  19. jQuery로 접속 주소(URL) 알아내기

    Date2021.03.25 Views228
    Read More
  20. jquery 사용자정의 속성의 사용

    Date2021.03.25 Views205
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 Next
/ 9

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved