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,268
17년 전 조회 1,979
17년 전 조회 2,301
17년 전 조회 3,115
17년 전 조회 1,381
17년 전 조회 1,442
17년 전 조회 1,697
17년 전 조회 1,363
17년 전 조회 4,498
17년 전 조회 4,033
17년 전 조회 2,921
17년 전 조회 1,719
17년 전 조회 1,459
17년 전 조회 1,743
17년 전 조회 2,673
17년 전 조회 1,864
17년 전 조회 2,144
17년 전 조회 1,426
17년 전 조회 1,173
17년 전 조회 1,249
17년 전 조회 3,059
17년 전 조회 2,606
17년 전 조회 2,167
17년 전 조회 2,184
17년 전 조회 1,922
17년 전 조회 2,367
17년 전 조회 2,147
17년 전 조회 2,108
17년 전 조회 2,003
17년 전 조회 1,317
17년 전 조회 1,943
17년 전 조회 2,354
17년 전 조회 2,443
17년 전 조회 1,768
17년 전 조회 1,627
17년 전 조회 1,491
17년 전 조회 2,707
17년 전 조회 2,798
17년 전 조회 2,203
17년 전 조회 2,557
17년 전 조회 2,853
17년 전 조회 1,444
17년 전 조회 1,307
17년 전 조회 6,470
17년 전 조회 1,309
17년 전 조회 1,760
17년 전 조회 1,907
17년 전 조회 1,222
17년 전 조회 1,311
17년 전 조회 2,008
17년 전 조회 1,647
17년 전 조회 3,765
17년 전 조회 1,334
17년 전 조회 2,042
17년 전 조회 1,286
17년 전 조회 1,528
17년 전 조회 2,510
17년 전 조회 2,151
17년 전 조회 1,154
17년 전 조회 1,167
17년 전 조회 1,232
17년 전 조회 6,176
17년 전 조회 5,981
17년 전 조회 2,175
17년 전 조회 1,146
17년 전 조회 1,257
17년 전 조회 2,220
17년 전 조회 1,624
17년 전 조회 1,285
17년 전 조회 1,315
17년 전 조회 1,248
17년 전 조회 1,185
17년 전 조회 4,094
17년 전 조회 2,306
17년 전 조회 1,756
17년 전 조회 2,903
17년 전 조회 1,591
17년 전 조회 1,270
17년 전 조회 1,303
17년 전 조회 1,361
17년 전 조회 1,250
17년 전 조회 1,356
17년 전 조회 2,532
17년 전 조회 4,339
17년 전 조회 1,310
17년 전 조회 4,068
17년 전 조회 4,223
17년 전 조회 1,343
17년 전 조회 2,301
17년 전 조회 1,748
17년 전 조회 3,349
17년 전 조회 1,490
17년 전 조회 3,732
17년 전 조회 3,527
17년 전 조회 2,704
17년 전 조회 3,071
17년 전 조회 2,757
17년 전 조회 2,077
17년 전 조회 3,437
17년 전 조회 2,769