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,308
17년 전 조회 2,021
17년 전 조회 2,343
17년 전 조회 3,157
17년 전 조회 1,420
17년 전 조회 1,483
17년 전 조회 1,731
17년 전 조회 1,403
17년 전 조회 4,538
17년 전 조회 4,082
17년 전 조회 2,965
17년 전 조회 1,755
17년 전 조회 1,488
17년 전 조회 1,782
17년 전 조회 2,715
17년 전 조회 1,908
17년 전 조회 2,180
17년 전 조회 1,468
17년 전 조회 1,212
17년 전 조회 1,286
17년 전 조회 3,099
17년 전 조회 2,643
17년 전 조회 2,208
17년 전 조회 2,228
17년 전 조회 1,966
17년 전 조회 2,407
17년 전 조회 2,187
17년 전 조회 2,142
17년 전 조회 2,034
17년 전 조회 1,357
17년 전 조회 1,989
17년 전 조회 2,397
17년 전 조회 2,479
17년 전 조회 1,802
17년 전 조회 1,665
17년 전 조회 1,525
17년 전 조회 2,748
17년 전 조회 2,835
17년 전 조회 2,237
17년 전 조회 2,585
17년 전 조회 2,888
17년 전 조회 1,486
17년 전 조회 1,346
17년 전 조회 6,505
17년 전 조회 1,343
17년 전 조회 1,804
17년 전 조회 1,946
17년 전 조회 1,262
17년 전 조회 1,337
17년 전 조회 2,046
17년 전 조회 1,686
17년 전 조회 3,798
17년 전 조회 1,371
17년 전 조회 2,084
17년 전 조회 1,328
17년 전 조회 1,569
17년 전 조회 2,551
17년 전 조회 2,194
17년 전 조회 1,184
17년 전 조회 1,208
17년 전 조회 1,269
17년 전 조회 6,217
17년 전 조회 6,027
17년 전 조회 2,211
17년 전 조회 1,178
17년 전 조회 1,293
17년 전 조회 2,261
17년 전 조회 1,661
17년 전 조회 1,318
17년 전 조회 1,343
17년 전 조회 1,287
17년 전 조회 1,222
17년 전 조회 4,136
17년 전 조회 2,350
17년 전 조회 1,795
17년 전 조회 2,937
17년 전 조회 1,626
17년 전 조회 1,315
17년 전 조회 1,343
17년 전 조회 1,397
17년 전 조회 1,287
17년 전 조회 1,393
17년 전 조회 2,576
17년 전 조회 4,377
17년 전 조회 1,345
17년 전 조회 4,111
17년 전 조회 4,260
17년 전 조회 1,373
17년 전 조회 2,342
17년 전 조회 1,789
17년 전 조회 3,383
17년 전 조회 1,529
17년 전 조회 3,774
17년 전 조회 3,562
17년 전 조회 2,743
17년 전 조회 3,108
17년 전 조회 2,805
17년 전 조회 2,124
17년 전 조회 3,478
17년 전 조회 2,808