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,256
17년 전 조회 1,968
17년 전 조회 2,285
17년 전 조회 3,099
17년 전 조회 1,366
17년 전 조회 1,431
17년 전 조회 1,680
17년 전 조회 1,351
17년 전 조회 4,480
17년 전 조회 4,015
17년 전 조회 2,911
17년 전 조회 1,705
17년 전 조회 1,445
17년 전 조회 1,723
17년 전 조회 2,653
17년 전 조회 1,851
17년 전 조회 2,130
17년 전 조회 1,410
17년 전 조회 1,160
17년 전 조회 1,235
17년 전 조회 3,046
17년 전 조회 2,586
17년 전 조회 2,158
17년 전 조회 2,172
17년 전 조회 1,906
17년 전 조회 2,353
17년 전 조회 2,133
17년 전 조회 2,096
17년 전 조회 1,985
17년 전 조회 1,307
17년 전 조회 1,931
17년 전 조회 2,344
17년 전 조회 2,432
17년 전 조회 1,754
17년 전 조회 1,619
17년 전 조회 1,482
17년 전 조회 2,695
17년 전 조회 2,789
17년 전 조회 2,185
17년 전 조회 2,537
17년 전 조회 2,844
17년 전 조회 1,435
17년 전 조회 1,298
17년 전 조회 6,452
17년 전 조회 1,290
17년 전 조회 1,746
17년 전 조회 1,892
17년 전 조회 1,210
17년 전 조회 1,295
17년 전 조회 1,999
17년 전 조회 1,630
17년 전 조회 3,753
17년 전 조회 1,320
17년 전 조회 2,035
17년 전 조회 1,273
17년 전 조회 1,513
17년 전 조회 2,496
17년 전 조회 2,135
17년 전 조회 1,140
17년 전 조회 1,156
17년 전 조회 1,221
17년 전 조회 6,163
17년 전 조회 5,968
17년 전 조회 2,162
17년 전 조회 1,136
17년 전 조회 1,239
17년 전 조회 2,201
17년 전 조회 1,611
17년 전 조회 1,272
17년 전 조회 1,296
17년 전 조회 1,232
17년 전 조회 1,169
17년 전 조회 4,083
17년 전 조회 2,289
17년 전 조회 1,743
17년 전 조회 2,891
17년 전 조회 1,581
17년 전 조회 1,258
17년 전 조회 1,281
17년 전 조회 1,348
17년 전 조회 1,236
17년 전 조회 1,345
17년 전 조회 2,523
17년 전 조회 4,320
17년 전 조회 1,294
17년 전 조회 4,058
17년 전 조회 4,212
17년 전 조회 1,323
17년 전 조회 2,284
17년 전 조회 1,731
17년 전 조회 3,339
17년 전 조회 1,475
17년 전 조회 3,719
17년 전 조회 3,517
17년 전 조회 2,684
17년 전 조회 3,057
17년 전 조회 2,744
17년 전 조회 2,065
17년 전 조회 3,426
17년 전 조회 2,754