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,239
17년 전 조회 1,947
17년 전 조회 2,263
17년 전 조회 3,081
17년 전 조회 1,349
17년 전 조회 1,417
17년 전 조회 1,654
17년 전 조회 1,333
17년 전 조회 4,462
17년 전 조회 4,004
17년 전 조회 2,891
17년 전 조회 1,689
17년 전 조회 1,431
17년 전 조회 1,702
17년 전 조회 2,630
17년 전 조회 1,837
17년 전 조회 2,117
17년 전 조회 1,396
17년 전 조회 1,139
17년 전 조회 1,216
17년 전 조회 3,026
17년 전 조회 2,567
17년 전 조회 2,143
17년 전 조회 2,152
17년 전 조회 1,895
17년 전 조회 2,340
17년 전 조회 2,118
17년 전 조회 2,082
17년 전 조회 1,972
17년 전 조회 1,297
17년 전 조회 1,916
17년 전 조회 2,332
17년 전 조회 2,413
17년 전 조회 1,744
17년 전 조회 1,595
17년 전 조회 1,465
17년 전 조회 2,674
17년 전 조회 2,773
17년 전 조회 2,170
17년 전 조회 2,516
17년 전 조회 2,824
17년 전 조회 1,419
17년 전 조회 1,278
17년 전 조회 6,435
17년 전 조회 1,277
17년 전 조회 1,726
17년 전 조회 1,876
17년 전 조회 1,192
17년 전 조회 1,282
17년 전 조회 1,988
17년 전 조회 1,617
17년 전 조회 3,741
17년 전 조회 1,307
17년 전 조회 2,018
17년 전 조회 1,259
17년 전 조회 1,498
17년 전 조회 2,470
17년 전 조회 2,116
17년 전 조회 1,127
17년 전 조회 1,141
17년 전 조회 1,204
17년 전 조회 6,143
17년 전 조회 5,948
17년 전 조회 2,140
17년 전 조회 1,115
17년 전 조회 1,222
17년 전 조회 2,182
17년 전 조회 1,596
17년 전 조회 1,258
17년 전 조회 1,284
17년 전 조회 1,213
17년 전 조회 1,151
17년 전 조회 4,064
17년 전 조회 2,271
17년 전 조회 1,725
17년 전 조회 2,871
17년 전 조회 1,559
17년 전 조회 1,239
17년 전 조회 1,267
17년 전 조회 1,336
17년 전 조회 1,220
17년 전 조회 1,326
17년 전 조회 2,509
17년 전 조회 4,298
17년 전 조회 1,281
17년 전 조회 4,046
17년 전 조회 4,194
17년 전 조회 1,304
17년 전 조회 2,271
17년 전 조회 1,718
17년 전 조회 3,322
17년 전 조회 1,454
17년 전 조회 3,699
17년 전 조회 3,502
17년 전 조회 2,667
17년 전 조회 3,034
17년 전 조회 2,726
17년 전 조회 2,046
17년 전 조회 3,404
17년 전 조회 2,732