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,232
17년 전 조회 1,940
17년 전 조회 2,257
17년 전 조회 3,067
17년 전 조회 1,340
17년 전 조회 1,417
17년 전 조회 1,649
17년 전 조회 1,326
17년 전 조회 4,456
17년 전 조회 3,997
17년 전 조회 2,880
17년 전 조회 1,685
17년 전 조회 1,424
17년 전 조회 1,690
17년 전 조회 2,621
17년 전 조회 1,831
17년 전 조회 2,112
17년 전 조회 1,388
17년 전 조회 1,133
17년 전 조회 1,208
17년 전 조회 3,017
17년 전 조회 2,556
17년 전 조회 2,134
17년 전 조회 2,140
17년 전 조회 1,887
17년 전 조회 2,335
17년 전 조회 2,109
17년 전 조회 2,073
17년 전 조회 1,961
17년 전 조회 1,291
17년 전 조회 1,908
17년 전 조회 2,322
17년 전 조회 2,404
17년 전 조회 1,732
17년 전 조회 1,590
17년 전 조회 1,454
17년 전 조회 2,669
17년 전 조회 2,761
17년 전 조회 2,154
17년 전 조회 2,510
17년 전 조회 2,813
17년 전 조회 1,411
17년 전 조회 1,264
17년 전 조회 6,423
17년 전 조회 1,264
17년 전 조회 1,719
17년 전 조회 1,865
17년 전 조회 1,186
17년 전 조회 1,275
17년 전 조회 1,978
17년 전 조회 1,611
17년 전 조회 3,719
17년 전 조회 1,298
17년 전 조회 2,005
17년 전 조회 1,253
17년 전 조회 1,489
17년 전 조회 2,454
17년 전 조회 2,107
17년 전 조회 1,119
17년 전 조회 1,128
17년 전 조회 1,193
17년 전 조회 6,136
17년 전 조회 5,936
17년 전 조회 2,125
17년 전 조회 1,106
17년 전 조회 1,213
17년 전 조회 2,169
17년 전 조회 1,591
17년 전 조회 1,245
17년 전 조회 1,272
17년 전 조회 1,203
17년 전 조회 1,144
17년 전 조회 4,049
17년 전 조회 2,260
17년 전 조회 1,710
17년 전 조회 2,854
17년 전 조회 1,553
17년 전 조회 1,236
17년 전 조회 1,263
17년 전 조회 1,328
17년 전 조회 1,213
17년 전 조회 1,320
17년 전 조회 2,489
17년 전 조회 4,282
17년 전 조회 1,275
17년 전 조회 4,027
17년 전 조회 4,187
17년 전 조회 1,299
17년 전 조회 2,264
17년 전 조회 1,705
17년 전 조회 3,311
17년 전 조회 1,445
17년 전 조회 3,686
17년 전 조회 3,485
17년 전 조회 2,649
17년 전 조회 3,019
17년 전 조회 2,715
17년 전 조회 2,030
17년 전 조회 3,397
17년 전 조회 2,717