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,164
17년 전 조회 1,864
17년 전 조회 2,158
17년 전 조회 2,971
17년 전 조회 1,249
17년 전 조회 1,341
17년 전 조회 1,570
17년 전 조회 1,231
17년 전 조회 4,368
17년 전 조회 3,907
17년 전 조회 2,797
17년 전 조회 1,596
17년 전 조회 1,343
17년 전 조회 1,609
17년 전 조회 2,530
17년 전 조회 1,745
17년 전 조회 2,028
17년 전 조회 1,319
17년 전 조회 1,048
17년 전 조회 1,131
17년 전 조회 2,932
17년 전 조회 2,472
17년 전 조회 2,052
17년 전 조회 2,051
17년 전 조회 1,805
17년 전 조회 2,251
17년 전 조회 2,022
17년 전 조회 1,996
17년 전 조회 1,881
17년 전 조회 1,214
17년 전 조회 1,836
17년 전 조회 2,238
17년 전 조회 2,311
17년 전 조회 1,648
17년 전 조회 1,516
17년 전 조회 1,366
17년 전 조회 2,586
17년 전 조회 2,679
17년 전 조회 2,072
17년 전 조회 2,425
17년 전 조회 2,729
17년 전 조회 1,330
17년 전 조회 1,194
17년 전 조회 6,335
17년 전 조회 1,181
17년 전 조회 1,633
17년 전 조회 1,784
17년 전 조회 1,106
17년 전 조회 1,199
17년 전 조회 1,898
17년 전 조회 1,528
17년 전 조회 3,628
17년 전 조회 1,212
17년 전 조회 1,917
17년 전 조회 1,173
17년 전 조회 1,392
17년 전 조회 2,366
17년 전 조회 2,023
17년 전 조회 1,043
17년 전 조회 1,046
17년 전 조회 1,094
17년 전 조회 6,050
17년 전 조회 5,858
17년 전 조회 2,037
17년 전 조회 1,028
17년 전 조회 1,128
17년 전 조회 2,090
17년 전 조회 1,521
17년 전 조회 1,166
17년 전 조회 1,193
17년 전 조회 1,133
17년 전 조회 1,051
17년 전 조회 3,966
17년 전 조회 2,174
17년 전 조회 1,622
17년 전 조회 2,771
17년 전 조회 1,480
17년 전 조회 1,161
17년 전 조회 1,180
17년 전 조회 1,251
17년 전 조회 1,138
17년 전 조회 1,252
17년 전 조회 2,404
17년 전 조회 4,196
17년 전 조회 1,196
17년 전 조회 3,954
17년 전 조회 4,108
17년 전 조회 1,217
17년 전 조회 2,187
17년 전 조회 1,626
17년 전 조회 3,223
17년 전 조회 1,362
17년 전 조회 3,607
17년 전 조회 3,398
17년 전 조회 2,571
17년 전 조회 2,940
17년 전 조회 2,634
17년 전 조회 1,950
17년 전 조회 3,320
17년 전 조회 2,628
🐛 버그신고