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,165
17년 전 조회 1,865
17년 전 조회 2,158
17년 전 조회 2,974
17년 전 조회 1,251
17년 전 조회 1,343
17년 전 조회 1,570
17년 전 조회 1,231
17년 전 조회 4,369
17년 전 조회 3,908
17년 전 조회 2,798
17년 전 조회 1,597
17년 전 조회 1,346
17년 전 조회 1,611
17년 전 조회 2,530
17년 전 조회 1,746
17년 전 조회 2,029
17년 전 조회 1,320
17년 전 조회 1,050
17년 전 조회 1,132
17년 전 조회 2,932
17년 전 조회 2,473
17년 전 조회 2,053
17년 전 조회 2,052
17년 전 조회 1,809
17년 전 조회 2,253
17년 전 조회 2,023
17년 전 조회 1,996
17년 전 조회 1,883
17년 전 조회 1,218
17년 전 조회 1,837
17년 전 조회 2,241
17년 전 조회 2,313
17년 전 조회 1,651
17년 전 조회 1,516
17년 전 조회 1,368
17년 전 조회 2,588
17년 전 조회 2,680
17년 전 조회 2,074
17년 전 조회 2,425
17년 전 조회 2,731
17년 전 조회 1,333
17년 전 조회 1,197
17년 전 조회 6,337
17년 전 조회 1,182
17년 전 조회 1,633
17년 전 조회 1,785
17년 전 조회 1,110
17년 전 조회 1,199
17년 전 조회 1,899
17년 전 조회 1,529
17년 전 조회 3,630
17년 전 조회 1,214
17년 전 조회 1,919
17년 전 조회 1,176
17년 전 조회 1,392
17년 전 조회 2,368
17년 전 조회 2,023
17년 전 조회 1,046
17년 전 조회 1,047
17년 전 조회 1,097
17년 전 조회 6,050
17년 전 조회 5,858
17년 전 조회 2,037
17년 전 조회 1,029
17년 전 조회 1,128
17년 전 조회 2,090
17년 전 조회 1,521
17년 전 조회 1,166
17년 전 조회 1,194
17년 전 조회 1,134
17년 전 조회 1,052
17년 전 조회 3,968
17년 전 조회 2,176
17년 전 조회 1,624
17년 전 조회 2,771
17년 전 조회 1,480
17년 전 조회 1,162
17년 전 조회 1,181
17년 전 조회 1,253
17년 전 조회 1,141
17년 전 조회 1,253
17년 전 조회 2,405
17년 전 조회 4,197
17년 전 조회 1,196
17년 전 조회 3,955
17년 전 조회 4,108
17년 전 조회 1,218
17년 전 조회 2,188
17년 전 조회 1,628
17년 전 조회 3,223
17년 전 조회 1,362
17년 전 조회 3,607
17년 전 조회 3,399
17년 전 조회 2,572
17년 전 조회 2,941
17년 전 조회 2,636
17년 전 조회 1,951
17년 전 조회 3,322
17년 전 조회 2,629
🐛 버그신고