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,520
17년 전 조회 2,205
17년 전 조회 2,539
17년 전 조회 3,350
17년 전 조회 1,637
17년 전 조회 1,702
17년 전 조회 1,942
17년 전 조회 1,614
17년 전 조회 4,748
17년 전 조회 4,267
17년 전 조회 3,193
17년 전 조회 1,961
17년 전 조회 1,697
17년 전 조회 1,972
17년 전 조회 2,905
17년 전 조회 2,107
17년 전 조회 2,397
17년 전 조회 1,693
17년 전 조회 1,428
17년 전 조회 1,516
17년 전 조회 3,281
17년 전 조회 2,859
17년 전 조회 2,415
17년 전 조회 2,433
17년 전 조회 2,187
17년 전 조회 2,621
17년 전 조회 2,407
17년 전 조회 2,349
17년 전 조회 2,259
17년 전 조회 1,567
17년 전 조회 2,192
17년 전 조회 2,621
17년 전 조회 2,697
17년 전 조회 2,025
17년 전 조회 1,864
17년 전 조회 1,741
17년 전 조회 2,958
17년 전 조회 3,043
17년 전 조회 2,444
17년 전 조회 2,803
17년 전 조회 3,092
17년 전 조회 1,691
17년 전 조회 1,531
17년 전 조회 6,720
17년 전 조회 1,548
17년 전 조회 2,003
17년 전 조회 2,147
17년 전 조회 1,477
17년 전 조회 1,556
17년 전 조회 2,248
17년 전 조회 1,897
17년 전 조회 4,015
17년 전 조회 1,578
17년 전 조회 2,277
17년 전 조회 1,545
17년 전 조회 1,762
17년 전 조회 2,747
17년 전 조회 2,415
17년 전 조회 1,397
17년 전 조회 1,413
17년 전 조회 1,473
17년 전 조회 6,428
17년 전 조회 6,236
17년 전 조회 2,416
17년 전 조회 1,403
17년 전 조회 1,528
17년 전 조회 2,463
17년 전 조회 1,869
17년 전 조회 1,535
17년 전 조회 1,554
17년 전 조회 1,481
17년 전 조회 1,446
17년 전 조회 4,359
17년 전 조회 2,576
17년 전 조회 1,995
17년 전 조회 3,137
17년 전 조회 1,832
17년 전 조회 1,521
17년 전 조회 1,561
17년 전 조회 1,618
17년 전 조회 1,507
17년 전 조회 1,609
17년 전 조회 2,793
17년 전 조회 4,611
17년 전 조회 1,549
17년 전 조회 4,310
17년 전 조회 4,479
17년 전 조회 1,592
17년 전 조회 2,575
17년 전 조회 2,001
17년 전 조회 3,609
17년 전 조회 1,745
17년 전 조회 4,014
17년 전 조회 3,789
17년 전 조회 2,968
17년 전 조회 3,336
17년 전 조회 3,044
17년 전 조회 2,353
17년 전 조회 3,704
17년 전 조회 3,036