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,383
17년 전 조회 2,073
17년 전 조회 2,409
17년 전 조회 3,220
17년 전 조회 1,482
17년 전 조회 1,547
17년 전 조회 1,806
17년 전 조회 1,473
17년 전 조회 4,607
17년 전 조회 4,144
17년 전 조회 3,049
17년 전 조회 1,822
17년 전 조회 1,559
17년 전 조회 1,860
17년 전 조회 2,782
17년 전 조회 1,973
17년 전 조회 2,260
17년 전 조회 1,538
17년 전 조회 1,287
17년 전 조회 1,360
17년 전 조회 3,158
17년 전 조회 2,715
17년 전 조회 2,283
17년 전 조회 2,310
17년 전 조회 2,040
17년 전 조회 2,478
17년 전 조회 2,270
17년 전 조회 2,214
17년 전 조회 2,117
17년 전 조회 1,414
17년 전 조회 2,069
17년 전 조회 2,469
17년 전 조회 2,562
17년 전 조회 1,875
17년 전 조회 1,723
17년 전 조회 1,602
17년 전 조회 2,816
17년 전 조회 2,898
17년 전 조회 2,315
17년 전 조회 2,657
17년 전 조회 2,962
17년 전 조회 1,560
17년 전 조회 1,406
17년 전 조회 6,584
17년 전 조회 1,412
17년 전 조회 1,867
17년 전 조회 2,018
17년 전 조회 1,333
17년 전 조회 1,409
17년 전 조회 2,101
17년 전 조회 1,746
17년 전 조회 3,879
17년 전 조회 1,441
17년 전 조회 2,152
17년 전 조회 1,393
17년 전 조회 1,641
17년 전 조회 2,615
17년 전 조회 2,262
17년 전 조회 1,248
17년 전 조회 1,264
17년 전 조회 1,330
17년 전 조회 6,285
17년 전 조회 6,103
17년 전 조회 2,282
17년 전 조회 1,252
17년 전 조회 1,370
17년 전 조회 2,336
17년 전 조회 1,727
17년 전 조회 1,388
17년 전 조회 1,413
17년 전 조회 1,343
17년 전 조회 1,297
17년 전 조회 4,207
17년 전 조회 2,424
17년 전 조회 1,868
17년 전 조회 3,009
17년 전 조회 1,703
17년 전 조회 1,376
17년 전 조회 1,424
17년 전 조회 1,470
17년 전 조회 1,365
17년 전 조회 1,462
17년 전 조회 2,649
17년 전 조회 4,458
17년 전 조회 1,412
17년 전 조회 4,178
17년 전 조회 4,334
17년 전 조회 1,440
17년 전 조회 2,413
17년 전 조회 1,864
17년 전 조회 3,455
17년 전 조회 1,596
17년 전 조회 3,845
17년 전 조회 3,654
17년 전 조회 2,818
17년 전 조회 3,172
17년 전 조회 2,884
17년 전 조회 2,190
17년 전 조회 3,549
17년 전 조회 2,885