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,383
17년 전 조회 2,071
17년 전 조회 2,407
17년 전 조회 3,217
17년 전 조회 1,480
17년 전 조회 1,544
17년 전 조회 1,805
17년 전 조회 1,470
17년 전 조회 4,606
17년 전 조회 4,143
17년 전 조회 3,046
17년 전 조회 1,821
17년 전 조회 1,557
17년 전 조회 1,858
17년 전 조회 2,777
17년 전 조회 1,972
17년 전 조회 2,258
17년 전 조회 1,537
17년 전 조회 1,286
17년 전 조회 1,357
17년 전 조회 3,156
17년 전 조회 2,714
17년 전 조회 2,280
17년 전 조회 2,304
17년 전 조회 2,036
17년 전 조회 2,477
17년 전 조회 2,268
17년 전 조회 2,212
17년 전 조회 2,114
17년 전 조회 1,412
17년 전 조회 2,066
17년 전 조회 2,465
17년 전 조회 2,559
17년 전 조회 1,874
17년 전 조회 1,722
17년 전 조회 1,600
17년 전 조회 2,815
17년 전 조회 2,896
17년 전 조회 2,312
17년 전 조회 2,655
17년 전 조회 2,960
17년 전 조회 1,558
17년 전 조회 1,404
17년 전 조회 6,582
17년 전 조회 1,410
17년 전 조회 1,866
17년 전 조회 2,014
17년 전 조회 1,333
17년 전 조회 1,409
17년 전 조회 2,098
17년 전 조회 1,745
17년 전 조회 3,878
17년 전 조회 1,441
17년 전 조회 2,151
17년 전 조회 1,391
17년 전 조회 1,637
17년 전 조회 2,613
17년 전 조회 2,260
17년 전 조회 1,248
17년 전 조회 1,263
17년 전 조회 1,327
17년 전 조회 6,282
17년 전 조회 6,100
17년 전 조회 2,281
17년 전 조회 1,250
17년 전 조회 1,365
17년 전 조회 2,336
17년 전 조회 1,727
17년 전 조회 1,384
17년 전 조회 1,410
17년 전 조회 1,341
17년 전 조회 1,296
17년 전 조회 4,205
17년 전 조회 2,423
17년 전 조회 1,867
17년 전 조회 3,006
17년 전 조회 1,700
17년 전 조회 1,374
17년 전 조회 1,421
17년 전 조회 1,467
17년 전 조회 1,365
17년 전 조회 1,458
17년 전 조회 2,647
17년 전 조회 4,457
17년 전 조회 1,409
17년 전 조회 4,176
17년 전 조회 4,331
17년 전 조회 1,437
17년 전 조회 2,412
17년 전 조회 1,860
17년 전 조회 3,453
17년 전 조회 1,594
17년 전 조회 3,843
17년 전 조회 3,651
17년 전 조회 2,817
17년 전 조회 3,171
17년 전 조회 2,882
17년 전 조회 2,188
17년 전 조회 3,547
17년 전 조회 2,883