반응형
[Javascript] number spinner
부제 : 버튼 꾹 누르면 숫자 계속 증가/감소하는 기능 구현
<Html>
<javascript>
var timerInterval;
var num = document.getElementById("num"); // 숫자 input box
// 버튼 눌렀을 때
function mousedown(el) {
timerInterval = setInterval(function () {
if (el.id === "up") { // up button
num.value = parseInt(num.value) + 1;
} else if (el.id === "down") { // down button
num.value = parseInt(num.value) - 1;
}
}, 100);
}
// 버튼 땠을 때
function mouseup() {
clearInterval(timerInterval);
}
반응형
'WEB > JavaScript' 카테고리의 다른 글
| [JavaScript] input 에 enter key 입력 이벤트 (0) | 2019.02.08 |
|---|---|
| [JavaScript] <input type="file"> 에서 CSV, Json 파일 읽는 방법 (0) | 2019.01.25 |
| [JavaScript] 클래스 제어 (0) | 2019.01.18 |
| [JavaScript] 웹 브라우저 확인 방법 (0) | 2019.01.17 |
| [JavaScript] Click event listener on class : class에 이벤트 추가 (0) | 2019.01.17 |