마우스 누르고 있으면 숫자 증가
[1초 이상 마우스 누르면 숫자 증가]
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js"></script>
<button id="counting">증가</button>
<input id="result_count" value="">
<script>
var cnt = 0;
var time = 100; //1000 = 1초
var interval = null;
function countup(){
cnt = cnt + 1;
$("#result_count").val(cnt).blur();
}
$("#counting").mousedown(function() {
interval = setInterval("countup()", time);
});
$("#counting").mouseup(function() {
clearInterval(interval);
});
</script>
결과보기
0.5초 이상 마우스 누르면 숫자 증가
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js"></script>
<button id="counting">증가</button>
<input id="result_count" value="">
<script>
//0.1초마다
var time = 100;//1000 = 1초
//0.5초뒤 실행
var chk_time = 500;
var cnt = 0;
var interval = null;
var chk_intv = null;
function countup(){
cnt = cnt + 1;
$("#result_count").val(cnt).blur();
}
function check_time(){
clearInterval(chk_intv);
interval = setInterval("countup()", time);
}
$("#counting").mousedown(function() {
chk_intv = setInterval("check_time()", chk_time);
});
$("#counting").mouseup(function() {
clearInterval(chk_intv);
clearInterval(interval);
});
</script>
결과보기
개노미 님 (221124) https://sir.kr/qa/480828