메뉴 건너뛰기

?

단축키

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. fadeIn() , fadeOut() 을 이용한 간단한 자동 그림 전환

    Date2021.03.26 Views285
    Read More
  2. 기본 동작 막기

    Date2021.03.25 Views287
    Read More
  3. jQuery - 드래그앤드롭(DragAndDrop)을 통한 파일 업로드

    Date2021.03.09 Views291
    Read More
  4. click에 따른 마우스 휠 on off

    Date2021.03.31 Views304
    Read More
  5. javascript, jQuery에서 루프 돌리기 예 (for, forEach, each)

    Date2021.03.25 Views311
    Read More
  6. 다중 select

    Date2021.03.31 Views316
    Read More
  7. 최초 접속시 css와 script가 로딩되지 않을때

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

    Date2021.03.25 Views329
    Read More
  9. jQuery - 드래그, 리사이즈 이벤트에 따른 영역 침범 막기

    Date2021.03.09 Views363
    Read More
  10. Cesium에서 canvas 화면 center 지점의 좌표 취득

    Date2021.03.25 Views373
    Read More
  11. ajax 동기화 처리하기

    Date2021.03.25 Views416
    Read More
  12. jQuery - radio, checkBox값 가져오기, 선택하기, 제어 등

    Date2021.03.09 Views543
    Read More
  13. SELECTBOX MULTIPLE 검색하기

    Date2021.03.26 Views572
    Read More
  14. jQuery - 클릭이벤트 동적 처리하기($("").click(), on('click') 차이)

    Date2021.03.09 Views580
    Read More
  15. 간단한 마우스 포인터 따라 다니기

    Date2021.03.26 Views594
    Read More
  16. jQuery - ajax xhr을 활용한 파일 업로드 진행 상태 확인하기

    Date2021.03.09 Views598
    Read More
  17. jQuery - checkbox 전체 선택, 해제 기능 및 단일 체크박스가 해제되었을때 전체 선택 해제 하기

    Date2021.03.09 Views613
    Read More
  18. 모달 띄우는 코드

    Date2021.03.25 Views657
    Read More
  19. JS 첵박스 샘플

    Date2019.06.04 Views694
    Read More
  20. 사업자 번호를 입력하면 자동으로 하이픈을 붙여줍니다.

    Date2020.08.24 Views704
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 Next
/ 9

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved