뽁

체크박스 시프트(shift) 멀티선택

· 2019-03-20 (수) 16:27:47 · 4250

고객 요청이 있어서 구글링~ 스택에서 찾았습니다.

 

체크박스 선택 후 시프트 클릭 후 원하는 곳 클릭하면 다중선택 됩니다.

게시판 목록의 체크박스에 적용해도 좋을 것 같아서 올려 봅니다.

 

기타 방법들도 링크 참고하세요~

 

 

$(function() {
    var $chkboxes = $('.chkbox');
    var lastChecked = null;

    $chkboxes.click(function(e) {
        if(!lastChecked) {
            lastChecked = this;
            return;
        }

        if(e.shiftKey) {
            var start = $chkboxes.index(this);
            var end = $chkboxes.index(lastChecked);

            $chkboxes.slice(Math.min(start,end), Math.max(start,end)+ 1).prop('checked', lastChecked.checked);

        }

        lastChecked = this;
    });
});

|
댓글을 작성하시려면 로그인이 필요합니다.

개발자팁

5,403건

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
PHP 19-06-24 조회 3,189
PHP 19-06-09 조회 3,811
MySQL 19-04-01 조회 4,864
jQuery 19-03-20 조회 4,251
node.js 19-02-12 조회 3,351
node.js 19-02-12 조회 3,086
node.js 19-02-12 조회 3,351
node.js 19-02-07 조회 3,326
node.js 19-02-07 조회 3,064
node.js 19-02-07 조회 3,210
node.js 19-02-04 조회 2,948
node.js 19-02-04 조회 2,923
node.js 19-02-04 조회 3,370
node.js 19-01-31 조회 2,479
node.js 19-01-31 조회 2,628
node.js 19-01-31 조회 3,106
node.js 19-01-28 조회 2,870
node.js 19-01-28 조회 2,952
node.js 19-01-28 조회 2,793
node.js 19-01-22 조회 3,124
node.js 19-01-22 조회 2,886
node.js 19-01-22 조회 3,310
node.js 19-01-16 조회 2,755
node.js
[node.js]
19-01-16 조회 2,650
node.js 19-01-16 조회 9,326
node.js 19-01-12 조회 4,404
node.js 19-01-12 조회 3,006
node.js 19-01-12 조회 3,152
node.js 19-01-11 조회 2,696
node.js 19-01-11 조회 4,051