WEB/JavaScript

[Javascript] number spinner

S0PH1A 2019. 1. 21. 23:53
반응형

[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);
}





반응형