조회 : 455
//============================================================================
// input text용 updown 버튼
//============================================================================
function input_print_updown(this_s,v_min,v_max,step){
//==========================
// 초기화
//==========================
if(this_s.type!='text'){return;}
this_s.value = parseFloat(this_s.value);
if(!isFinite(step))step=1;
if(isFinite(v_max) && this_s.value>=v_max){this_s.value=v_max;}
if(isFinite(v_min) && this_s.value<=v_min){this_s.value=v_min;}
//==========================
// SPAN에 출력후 textbox를 속에 넣는다
//========================== if(!step) step=1;
var span = document.createElement('span');
//span.style.borderStyle='solid';
if (this_s.nextSibling)
this_s.parentNode.insertBefore(span,this_s.nextSibling);
else this_s.parentNode.appendChild(span);
span.appendChild(this_s);
//==========================
// 버튼 생성부
//==========================
var input_m = document.createElement('input');
input_m.type='button';
input_m.value='-';
input_m.className = this_s.className;
input_m.style.fontSize = this_s.style.fontSize;
input_p = input_m.cloneNode(input_m);
input_p.value='+';
//==========================
// 버튼 이벤트 생성부
//==========================
to =null;
var to_clear = function(){ clearTimeout(to); }//타임아웃 클리어
var m = function(){
var t = parseFloat(this_s.value);
if(isFinite(v_min) && t<=v_min){to_clear();return;}
this_s.value=t-step;
}
var m_d = function(){
m();to = setTimeout(m_d,200);
}
var p = function(){
var t = parseFloat(this_s.value);
if(isFinite(v_max) && t>=v_max){to_clear();return;}
this_s.value=t+step;
}
var p_d = function(){
p();to = setTimeout(p_d,200);
}
input_m.onmousedown = m_d;
input_m.onmouseout = to_clear;
input_m.onmouseup = to_clear;
input_p.onmousedown = p_d;
input_p.onmouseout = to_clear;
input_p.onmouseup = to_clear;
//==========================
// 버튼을 붙인다.
//==========================
span.appendChild(input_m);
span.appendChild(input_p);
}
<input name="test" type="text" id="test" value="20" size="5" maxlength="5" />
<script>input_print_updown(document.getElementById('test'),0,50);</script>
예전 버전도 있는데.. 삽질이 심해서... 간단하게.
| 제목 |
|---|
| [기본형] HTML (with 부트스트랩5.3 , jquery 3.7, vue.js) |
| 유용한 리눅스(LINUX) 명령어 |
| [공지] 기술 게시판 |
일 |
월 |
화 |
수 |
목 |
금 |
토 |
|---|---|---|---|---|---|---|
|
11.30
|
12.1
|
12.2
|
12.3
|
12.4
|
12.5
|
12.6
|
|
12.7
|
12.8
|
12.9
|
12.10
|
12.11
|
12.12
|
12.13
|
|
12.14
|
12.15
|
12.16
|
12.17
|
12.18
|
12.19
|
12.20
|
|
12.21
|
12.22
|
12.23
|
12.24
|
12.25
|
12.26
|
12.27
|
|
12.28
|
12.29
|
12.30
|
12.31
|
1.1
|
1.2
|
1.3
|