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,166
17년 전 조회 1,869
17년 전 조회 2,161
17년 전 조회 2,976
17년 전 조회 1,252
17년 전 조회 1,344
17년 전 조회 1,571
17년 전 조회 1,233
17년 전 조회 4,370
17년 전 조회 3,912
17년 전 조회 2,802
17년 전 조회 1,602
17년 전 조회 1,347
17년 전 조회 1,616
17년 전 조회 2,533
17년 전 조회 1,746
17년 전 조회 2,032
17년 전 조회 1,322
17년 전 조회 1,052
17년 전 조회 1,134
17년 전 조회 2,934
17년 전 조회 2,474
17년 전 조회 2,053
17년 전 조회 2,054
17년 전 조회 1,810
17년 전 조회 2,253
17년 전 조회 2,025
17년 전 조회 1,998
17년 전 조회 1,886
17년 전 조회 1,219
17년 전 조회 1,838
17년 전 조회 2,242
17년 전 조회 2,314
17년 전 조회 1,654
17년 전 조회 1,517
17년 전 조회 1,370
17년 전 조회 2,590
17년 전 조회 2,683
17년 전 조회 2,077
17년 전 조회 2,431
17년 전 조회 2,733
17년 전 조회 1,336
17년 전 조회 1,198
17년 전 조회 6,339
17년 전 조회 1,187
17년 전 조회 1,635
17년 전 조회 1,785
17년 전 조회 1,111
17년 전 조회 1,200
17년 전 조회 1,901
17년 전 조회 1,531
17년 전 조회 3,634
17년 전 조회 1,217
17년 전 조회 1,923
17년 전 조회 1,179
17년 전 조회 1,393
17년 전 조회 2,370
17년 전 조회 2,024
17년 전 조회 1,048
17년 전 조회 1,049
17년 전 조회 1,099
17년 전 조회 6,051
17년 전 조회 5,860
17년 전 조회 2,041
17년 전 조회 1,035
17년 전 조회 1,131
17년 전 조회 2,092
17년 전 조회 1,524
17년 전 조회 1,168
17년 전 조회 1,195
17년 전 조회 1,135
17년 전 조회 1,055
17년 전 조회 3,969
17년 전 조회 2,177
17년 전 조회 1,630
17년 전 조회 2,773
17년 전 조회 1,481
17년 전 조회 1,165
17년 전 조회 1,183
17년 전 조회 1,254
17년 전 조회 1,143
17년 전 조회 1,254
17년 전 조회 2,410
17년 전 조회 4,200
17년 전 조회 1,200
17년 전 조회 3,956
17년 전 조회 4,110
17년 전 조회 1,224
17년 전 조회 2,190
17년 전 조회 1,631
17년 전 조회 3,226
17년 전 조회 1,365
17년 전 조회 3,610
17년 전 조회 3,401
17년 전 조회 2,574
17년 전 조회 2,942
17년 전 조회 2,637
17년 전 조회 1,951
17년 전 조회 3,323
17년 전 조회 2,633
🐛 버그신고