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,418
17년 전 조회 2,096
17년 전 조회 2,438
17년 전 조회 3,253
17년 전 조회 1,518
17년 전 조회 1,587
17년 전 조회 1,832
17년 전 조회 1,512
17년 전 조회 4,642
17년 전 조회 4,176
17년 전 조회 3,076
17년 전 조회 1,858
17년 전 조회 1,603
17년 전 조회 1,880
17년 전 조회 2,806
17년 전 조회 2,009
17년 전 조회 2,288
17년 전 조회 1,569
17년 전 조회 1,318
17년 전 조회 1,391
17년 전 조회 3,179
17년 전 조회 2,736
17년 전 조회 2,304
17년 전 조회 2,336
17년 전 조회 2,075
17년 전 조회 2,508
17년 전 조회 2,297
17년 전 조회 2,242
17년 전 조회 2,144
17년 전 조회 1,448
17년 전 조회 2,094
17년 전 조회 2,502
17년 전 조회 2,584
17년 전 조회 1,892
17년 전 조회 1,751
17년 전 조회 1,629
17년 전 조회 2,847
17년 전 조회 2,932
17년 전 조회 2,343
17년 전 조회 2,694
17년 전 조회 2,988
17년 전 조회 1,590
17년 전 조회 1,425
17년 전 조회 6,608
17년 전 조회 1,447
17년 전 조회 1,894
17년 전 조회 2,049
17년 전 조회 1,360
17년 전 조회 1,449
17년 전 조회 2,132
17년 전 조회 1,781
17년 전 조회 3,895
17년 전 조회 1,470
17년 전 조회 2,175
17년 전 조회 1,426
17년 전 조회 1,665
17년 전 조회 2,635
17년 전 조회 2,285
17년 전 조회 1,279
17년 전 조회 1,301
17년 전 조회 1,352
17년 전 조회 6,312
17년 전 조회 6,126
17년 전 조회 2,299
17년 전 조회 1,290
17년 전 조회 1,405
17년 전 조회 2,364
17년 전 조회 1,758
17년 전 조회 1,420
17년 전 조회 1,442
17년 전 조회 1,372
17년 전 조회 1,328
17년 전 조회 4,230
17년 전 조회 2,450
17년 전 조회 1,894
17년 전 조회 3,035
17년 전 조회 1,723
17년 전 조회 1,403
17년 전 조회 1,445
17년 전 조회 1,494
17년 전 조회 1,396
17년 전 조회 1,498
17년 전 조회 2,673
17년 전 조회 4,483
17년 전 조회 1,438
17년 전 조회 4,199
17년 전 조회 4,357
17년 전 조회 1,478
17년 전 조회 2,443
17년 전 조회 1,885
17년 전 조회 3,488
17년 전 조회 1,629
17년 전 조회 3,870
17년 전 조회 3,673
17년 전 조회 2,840
17년 전 조회 3,197
17년 전 조회 2,905
17년 전 조회 2,214
17년 전 조회 3,578
17년 전 조회 2,907