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,310
17년 전 조회 2,024
17년 전 조회 2,344
17년 전 조회 3,158
17년 전 조회 1,421
17년 전 조회 1,484
17년 전 조회 1,734
17년 전 조회 1,406
17년 전 조회 4,538
17년 전 조회 4,082
17년 전 조회 2,973
17년 전 조회 1,756
17년 전 조회 1,489
17년 전 조회 1,787
17년 전 조회 2,718
17년 전 조회 1,909
17년 전 조회 2,182
17년 전 조회 1,471
17년 전 조회 1,213
17년 전 조회 1,287
17년 전 조회 3,099
17년 전 조회 2,645
17년 전 조회 2,211
17년 전 조회 2,229
17년 전 조회 1,967
17년 전 조회 2,408
17년 전 조회 2,188
17년 전 조회 2,142
17년 전 조회 2,037
17년 전 조회 1,358
17년 전 조회 1,991
17년 전 조회 2,399
17년 전 조회 2,479
17년 전 조회 1,805
17년 전 조회 1,667
17년 전 조회 1,526
17년 전 조회 2,749
17년 전 조회 2,836
17년 전 조회 2,240
17년 전 조회 2,587
17년 전 조회 2,888
17년 전 조회 1,487
17년 전 조회 1,347
17년 전 조회 6,507
17년 전 조회 1,344
17년 전 조회 1,804
17년 전 조회 1,948
17년 전 조회 1,262
17년 전 조회 1,339
17년 전 조회 2,047
17년 전 조회 1,688
17년 전 조회 3,804
17년 전 조회 1,374
17년 전 조회 2,088
17년 전 조회 1,330
17년 전 조회 1,571
17년 전 조회 2,553
17년 전 조회 2,198
17년 전 조회 1,186
17년 전 조회 1,209
17년 전 조회 1,271
17년 전 조회 6,219
17년 전 조회 6,031
17년 전 조회 2,212
17년 전 조회 1,180
17년 전 조회 1,297
17년 전 조회 2,263
17년 전 조회 1,662
17년 전 조회 1,323
17년 전 조회 1,345
17년 전 조회 1,289
17년 전 조회 1,223
17년 전 조회 4,137
17년 전 조회 2,352
17년 전 조회 1,799
17년 전 조회 2,938
17년 전 조회 1,628
17년 전 조회 1,315
17년 전 조회 1,343
17년 전 조회 1,401
17년 전 조회 1,290
17년 전 조회 1,396
17년 전 조회 2,578
17년 전 조회 4,380
17년 전 조회 1,346
17년 전 조회 4,112
17년 전 조회 4,266
17년 전 조회 1,373
17년 전 조회 2,343
17년 전 조회 1,793
17년 전 조회 3,385
17년 전 조회 1,532
17년 전 조회 3,777
17년 전 조회 3,562
17년 전 조회 2,744
17년 전 조회 3,109
17년 전 조회 2,806
17년 전 조회 2,126
17년 전 조회 3,481
17년 전 조회 2,811