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,375
17년 전 조회 2,065
17년 전 조회 2,403
17년 전 조회 3,212
17년 전 조회 1,475
17년 전 조회 1,539
17년 전 조회 1,801
17년 전 조회 1,462
17년 전 조회 4,600
17년 전 조회 4,138
17년 전 조회 3,043
17년 전 조회 1,813
17년 전 조회 1,552
17년 전 조회 1,850
17년 전 조회 2,773
17년 전 조회 1,962
17년 전 조회 2,250
17년 전 조회 1,531
17년 전 조회 1,279
17년 전 조회 1,349
17년 전 조회 3,150
17년 전 조회 2,712
17년 전 조회 2,276
17년 전 조회 2,299
17년 전 조회 2,032
17년 전 조회 2,472
17년 전 조회 2,259
17년 전 조회 2,207
17년 전 조회 2,110
17년 전 조회 1,409
17년 전 조회 2,057
17년 전 조회 2,457
17년 전 조회 2,554
17년 전 조회 1,867
17년 전 조회 1,719
17년 전 조회 1,593
17년 전 조회 2,809
17년 전 조회 2,893
17년 전 조회 2,304
17년 전 조회 2,650
17년 전 조회 2,956
17년 전 조회 1,554
17년 전 조회 1,398
17년 전 조회 6,575
17년 전 조회 1,402
17년 전 조회 1,860
17년 전 조회 2,010
17년 전 조회 1,326
17년 전 조회 1,401
17년 전 조회 2,091
17년 전 조회 1,740
17년 전 조회 3,874
17년 전 조회 1,433
17년 전 조회 2,145
17년 전 조회 1,383
17년 전 조회 1,635
17년 전 조회 2,610
17년 전 조회 2,256
17년 전 조회 1,242
17년 전 조회 1,259
17년 전 조회 1,321
17년 전 조회 6,276
17년 전 조회 6,093
17년 전 조회 2,276
17년 전 조회 1,242
17년 전 조회 1,361
17년 전 조회 2,331
17년 전 조회 1,719
17년 전 조회 1,376
17년 전 조회 1,403
17년 전 조회 1,338
17년 전 조회 1,288
17년 전 조회 4,199
17년 전 조회 2,419
17년 전 조회 1,863
17년 전 조회 3,002
17년 전 조회 1,692
17년 전 조회 1,367
17년 전 조회 1,410
17년 전 조회 1,459
17년 전 조회 1,359
17년 전 조회 1,451
17년 전 조회 2,641
17년 전 조회 4,449
17년 전 조회 1,403
17년 전 조회 4,171
17년 전 조회 4,322
17년 전 조회 1,431
17년 전 조회 2,404
17년 전 조회 1,853
17년 전 조회 3,449
17년 전 조회 1,587
17년 전 조회 3,839
17년 전 조회 3,645
17년 전 조회 2,813
17년 전 조회 3,165
17년 전 조회 2,874
17년 전 조회 2,182
17년 전 조회 3,540
17년 전 조회 2,875