언어별 학습 자료/Javascript
"# JavaScript 30" 강의 - 10. Hold Shift and Check Checkboxes
CarpediemMementomori
2020. 10. 8. 17:14
학습일자
2020.10.08
학습내용
- 이메일이나 게시물을 shift key 누른 상태에서 클릭하면 범위 설정해서 자동으로 check 할 수 있도록 하는 내용
알게된 점
- 이벤트 객체 내에 shiftKey 속성이 있음(true/false)

- this.checked로 접근하는 이유는 console.dir(this)로 확인해보면, checked 속성이 있음(true or false)

- 이해가 안됨 (lastChecked의 역할이 무엇?)
function handleCheck(e) {
let inBetween = false;
if (e.shiftKey && this.checked) {
checkboxes.forEach((checkbox) => {
if (checkbox === this || checkbox === lastChecked) {
inBetween = !inBetween;
console.log("Starting to check them in between!");
}
if (inBetween) {checkbox.checked = true;}
});
}
lastChecked = this;
}
