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,152
17년 전 조회 1,849
17년 전 조회 2,149
17년 전 조회 2,961
17년 전 조회 1,238
17년 전 조회 1,328
17년 전 조회 1,554
17년 전 조회 1,221
17년 전 조회 4,353
17년 전 조회 3,897
17년 전 조회 2,784
17년 전 조회 1,587
17년 전 조회 1,332
17년 전 조회 1,599
17년 전 조회 2,514
17년 전 조회 1,731
17년 전 조회 2,015
17년 전 조회 1,302
17년 전 조회 1,034
17년 전 조회 1,118
17년 전 조회 2,920
17년 전 조회 2,458
17년 전 조회 2,039
17년 전 조회 2,039
17년 전 조회 1,792
17년 전 조회 2,238
17년 전 조회 2,010
17년 전 조회 1,983
17년 전 조회 1,871
17년 전 조회 1,207
17년 전 조회 1,823
17년 전 조회 2,226
17년 전 조회 2,297
17년 전 조회 1,637
17년 전 조회 1,506
17년 전 조회 1,354
17년 전 조회 2,573
17년 전 조회 2,669
17년 전 조회 2,066
17년 전 조회 2,412
17년 전 조회 2,718
17년 전 조회 1,320
17년 전 조회 1,186
17년 전 조회 6,320
17년 전 조회 1,171
17년 전 조회 1,621
17년 전 조회 1,771
17년 전 조회 1,094
17년 전 조회 1,187
17년 전 조회 1,887
17년 전 조회 1,518
17년 전 조회 3,616
17년 전 조회 1,202
17년 전 조회 1,906
17년 전 조회 1,164
17년 전 조회 1,379
17년 전 조회 2,358
17년 전 조회 2,010
17년 전 조회 1,033
17년 전 조회 1,036
17년 전 조회 1,088
17년 전 조회 6,043
17년 전 조회 5,847
17년 전 조회 2,023
17년 전 조회 1,018
17년 전 조회 1,113
17년 전 조회 2,078
17년 전 조회 1,509
17년 전 조회 1,155
17년 전 조회 1,182
17년 전 조회 1,125
17년 전 조회 1,039
17년 전 조회 3,954
17년 전 조회 2,160
17년 전 조회 1,615
17년 전 조회 2,759
17년 전 조회 1,465
17년 전 조회 1,149
17년 전 조회 1,171
17년 전 조회 1,238
17년 전 조회 1,124
17년 전 조회 1,242
17년 전 조회 2,393
17년 전 조회 4,181
17년 전 조회 1,183
17년 전 조회 3,944
17년 전 조회 4,094
17년 전 조회 1,209
17년 전 조회 2,173
17년 전 조회 1,617
17년 전 조회 3,210
17년 전 조회 1,351
17년 전 조회 3,594
17년 전 조회 3,385
17년 전 조회 2,557
17년 전 조회 2,931
17년 전 조회 2,622
17년 전 조회 1,939
17년 전 조회 3,308
17년 전 조회 2,618
🐛 버그신고