R

텍스트 필드에 숫자 입력시 3자리 단위로 , 찍는 소스

<form name= form>
<input class="field" name=money onkeyup="number_format(this)">
</form>

<script language="javascript">
function number_format(f) {
 var val = f.value;
 var len = val.length;
    var number_format1 = "", number_format2 = "";
 var c = 0;
 
 if(val.charCodeAt(len-1)<48 || val.charCodeAt(len-1)>57) {
  alert("숫자만 입력해주세요");
  f.value = val.substr(0, (len-1));
 }else{
     if(len > 3) {   
         for(i = 0 ; i < len; i++){
    one = val.charAt(i)
    if(one != ",") number_format1 += one;
         }
   var number_format1_len = number_format1.length;
   var in_c = number_format1_len%3;
   if(!in_c) in_c = 3;
   
   for(i = 0 ; i < number_format1_len; i++){
    number_format2_one = number_format1.charAt(i)
    if(i == in_c){
     number_format2 += ",";
     in_c = 3+in_c;
    }
    number_format2 += number_format2_one;
         }
         f.value = number_format2;
     }
 }
}
</script>

[이 게시물은 관리자님에 의해 2011-10-31 16:57:14 JavaScript에서 이동 됨]
|

댓글 1개

좋네요~ 근데 이거 사용하면 데이터에 컴마가 추가되는 거죠?
댓글을 작성하시려면 로그인이 필요합니다. 로그인

프로그램

+
제목 글쓴이 날짜 조회
17년 전 조회 1,156
17년 전 조회 1,853
17년 전 조회 2,150
17년 전 조회 2,963
17년 전 조회 1,241
17년 전 조회 1,329
17년 전 조회 1,557
17년 전 조회 1,224
17년 전 조회 4,355
17년 전 조회 3,899
17년 전 조회 2,789
17년 전 조회 1,591
17년 전 조회 1,335
17년 전 조회 1,604
17년 전 조회 2,520
17년 전 조회 1,734
17년 전 조회 2,018
17년 전 조회 1,306
17년 전 조회 1,039
17년 전 조회 1,121
17년 전 조회 2,924
17년 전 조회 2,460
17년 전 조회 2,042
17년 전 조회 2,042
17년 전 조회 1,795
17년 전 조회 2,241
17년 전 조회 2,014
17년 전 조회 1,987
17년 전 조회 1,875
17년 전 조회 1,209
17년 전 조회 1,827
17년 전 조회 2,228
17년 전 조회 2,300
17년 전 조회 1,640
17년 전 조회 1,509
17년 전 조회 1,359
17년 전 조회 2,577
17년 전 조회 2,673
17년 전 조회 2,068
17년 전 조회 2,415
17년 전 조회 2,722
17년 전 조회 1,323
17년 전 조회 1,190
17년 전 조회 6,323
17년 전 조회 1,174
17년 전 조회 1,625
17년 전 조회 1,774
17년 전 조회 1,099
17년 전 조회 1,190
17년 전 조회 1,892
17년 전 조회 1,520
17년 전 조회 3,618
17년 전 조회 1,206
17년 전 조회 1,909
17년 전 조회 1,167
17년 전 조회 1,382
17년 전 조회 2,360
17년 전 조회 2,013
17년 전 조회 1,036
17년 전 조회 1,038
17년 전 조회 1,091
17년 전 조회 6,045
17년 전 조회 5,851
17년 전 조회 2,027
17년 전 조회 1,022
17년 전 조회 1,120
17년 전 조회 2,080
17년 전 조회 1,512
17년 전 조회 1,158
17년 전 조회 1,184
17년 전 조회 1,127
17년 전 조회 1,043
17년 전 조회 3,957
17년 전 조회 2,167
17년 전 조회 1,619
17년 전 조회 2,765
17년 전 조회 1,468
17년 전 조회 1,152
17년 전 조회 1,173
17년 전 조회 1,242
17년 전 조회 1,129
17년 전 조회 1,244
17년 전 조회 2,397
17년 전 조회 4,185
17년 전 조회 1,186
17년 전 조회 3,946
17년 전 조회 4,096
17년 전 조회 1,212
17년 전 조회 2,176
17년 전 조회 1,621
17년 전 조회 3,214
17년 전 조회 1,355
17년 전 조회 3,597
17년 전 조회 3,390
17년 전 조회 2,562
17년 전 조회 2,937
17년 전 조회 2,625
17년 전 조회 1,941
17년 전 조회 3,312
17년 전 조회 2,622
🐛 버그신고