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,305
17년 전 조회 2,014
17년 전 조회 2,338
17년 전 조회 3,152
17년 전 조회 1,416
17년 전 조회 1,479
17년 전 조회 1,730
17년 전 조회 1,395
17년 전 조회 4,535
17년 전 조회 4,080
17년 전 조회 2,958
17년 전 조회 1,753
17년 전 조회 1,483
17년 전 조회 1,781
17년 전 조회 2,706
17년 전 조회 1,902
17년 전 조회 2,179
17년 전 조회 1,464
17년 전 조회 1,207
17년 전 조회 1,278
17년 전 조회 3,096
17년 전 조회 2,638
17년 전 조회 2,206
17년 전 조회 2,224
17년 전 조회 1,965
17년 전 조회 2,401
17년 전 조회 2,183
17년 전 조회 2,139
17년 전 조회 2,030
17년 전 조회 1,354
17년 전 조회 1,983
17년 전 조회 2,392
17년 전 조회 2,479
17년 전 조회 1,796
17년 전 조회 1,662
17년 전 조회 1,525
17년 전 조회 2,743
17년 전 조회 2,831
17년 전 조회 2,232
17년 전 조회 2,580
17년 전 조회 2,884
17년 전 조회 1,483
17년 전 조회 1,343
17년 전 조회 6,500
17년 전 조회 1,339
17년 전 조회 1,798
17년 전 조회 1,940
17년 전 조회 1,257
17년 전 조회 1,334
17년 전 조회 2,043
17년 전 조회 1,682
17년 전 조회 3,794
17년 전 조회 1,369
17년 전 조회 2,076
17년 전 조회 1,324
17년 전 조회 1,563
17년 전 조회 2,547
17년 전 조회 2,188
17년 전 조회 1,182
17년 전 조회 1,201
17년 전 조회 1,267
17년 전 조회 6,214
17년 전 조회 6,020
17년 전 조회 2,205
17년 전 조회 1,172
17년 전 조회 1,290
17년 전 조회 2,257
17년 전 조회 1,659
17년 전 조회 1,314
17년 전 조회 1,340
17년 전 조회 1,284
17년 전 조회 1,217
17년 전 조회 4,132
17년 전 조회 2,343
17년 전 조회 1,790
17년 전 조회 2,933
17년 전 조회 1,625
17년 전 조회 1,311
17년 전 조회 1,335
17년 전 조회 1,394
17년 전 조회 1,281
17년 전 조회 1,389
17년 전 조회 2,571
17년 전 조회 4,373
17년 전 조회 1,342
17년 전 조회 4,103
17년 전 조회 4,258
17년 전 조회 1,372
17년 전 조회 2,337
17년 전 조회 1,785
17년 전 조회 3,380
17년 전 조회 1,525
17년 전 조회 3,769
17년 전 조회 3,556
17년 전 조회 2,738
17년 전 조회 3,106
17년 전 조회 2,797
17년 전 조회 2,117
17년 전 조회 3,471
17년 전 조회 2,804