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,173
17년 전 조회 1,876
17년 전 조회 2,174
17년 전 조회 2,987
17년 전 조회 1,258
17년 전 조회 1,351
17년 전 조회 1,578
17년 전 조회 1,238
17년 전 조회 4,375
17년 전 조회 3,919
17년 전 조회 2,810
17년 전 조회 1,609
17년 전 조회 1,354
17년 전 조회 1,626
17년 전 조회 2,538
17년 전 조회 1,754
17년 전 조회 2,039
17년 전 조회 1,329
17년 전 조회 1,062
17년 전 조회 1,140
17년 전 조회 2,943
17년 전 조회 2,482
17년 전 조회 2,060
17년 전 조회 2,064
17년 전 조회 1,814
17년 전 조회 2,266
17년 전 조회 2,036
17년 전 조회 2,007
17년 전 조회 1,893
17년 전 조회 1,229
17년 전 조회 1,847
17년 전 조회 2,246
17년 전 조회 2,323
17년 전 조회 1,662
17년 전 조회 1,526
17년 전 조회 1,379
17년 전 조회 2,596
17년 전 조회 2,690
17년 전 조회 2,085
17년 전 조회 2,436
17년 전 조회 2,737
17년 전 조회 1,341
17년 전 조회 1,209
17년 전 조회 6,347
17년 전 조회 1,189
17년 전 조회 1,647
17년 전 조회 1,790
17년 전 조회 1,121
17년 전 조회 1,208
17년 전 조회 1,908
17년 전 조회 1,536
17년 전 조회 3,642
17년 전 조회 1,223
17년 전 조회 1,932
17년 전 조회 1,183
17년 전 조회 1,401
17년 전 조회 2,377
17년 전 조회 2,032
17년 전 조회 1,054
17년 전 조회 1,057
17년 전 조회 1,113
17년 전 조회 6,064
17년 전 조회 5,868
17년 전 조회 2,050
17년 전 조회 1,039
17년 전 조회 1,137
17년 전 조회 2,098
17년 전 조회 1,531
17년 전 조회 1,175
17년 전 조회 1,203
17년 전 조회 1,144
17년 전 조회 1,064
17년 전 조회 3,976
17년 전 조회 2,188
17년 전 조회 1,637
17년 전 조회 2,781
17년 전 조회 1,484
17년 전 조회 1,172
17년 전 조회 1,194
17년 전 조회 1,257
17년 전 조회 1,146
17년 전 조회 1,261
17년 전 조회 2,419
17년 전 조회 4,212
17년 전 조회 1,207
17년 전 조회 3,961
17년 전 조회 4,118
17년 전 조회 1,229
17년 전 조회 2,195
17년 전 조회 1,638
17년 전 조회 3,233
17년 전 조회 1,374
17년 전 조회 3,618
17년 전 조회 3,407
17년 전 조회 2,580
17년 전 조회 2,954
17년 전 조회 2,645
17년 전 조회 1,956
17년 전 조회 3,330
17년 전 조회 2,642