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

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

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

 

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

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

 

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

 

 

$(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,159
PHP 19-06-09 조회 3,776
MySQL 19-04-01 조회 4,820
jQuery 19-03-20 조회 4,217
node.js 19-02-12 조회 3,314
node.js 19-02-12 조회 3,045
node.js 19-02-12 조회 3,311
node.js 19-02-07 조회 3,277
node.js 19-02-07 조회 3,030
node.js 19-02-07 조회 3,164
node.js 19-02-04 조회 2,900
node.js 19-02-04 조회 2,891
node.js 19-02-04 조회 3,321
node.js 19-01-31 조회 2,431
node.js 19-01-31 조회 2,577
node.js 19-01-31 조회 3,075
node.js 19-01-28 조회 2,836
node.js 19-01-28 조회 2,916
node.js 19-01-28 조회 2,742
node.js 19-01-22 조회 3,084
node.js 19-01-22 조회 2,836
node.js 19-01-22 조회 3,270
node.js 19-01-16 조회 2,706
node.js
[node.js]
19-01-16 조회 2,614
node.js 19-01-16 조회 9,289
node.js 19-01-12 조회 4,362
node.js 19-01-12 조회 2,982
node.js 19-01-12 조회 3,107
node.js 19-01-11 조회 2,682
node.js 19-01-11 조회 3,992