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,318
17년 전 조회 2,029
17년 전 조회 2,350
17년 전 조회 3,163
17년 전 조회 1,428
17년 전 조회 1,490
17년 전 조회 1,742
17년 전 조회 1,411
17년 전 조회 4,544
17년 전 조회 4,087
17년 전 조회 2,979
17년 전 조회 1,761
17년 전 조회 1,501
17년 전 조회 1,795
17년 전 조회 2,724
17년 전 조회 1,914
17년 전 조회 2,187
17년 전 조회 1,473
17년 전 조회 1,224
17년 전 조회 1,294
17년 전 조회 3,102
17년 전 조회 2,649
17년 전 조회 2,217
17년 전 조회 2,234
17년 전 조회 1,971
17년 전 조회 2,416
17년 전 조회 2,195
17년 전 조회 2,150
17년 전 조회 2,046
17년 전 조회 1,364
17년 전 조회 1,999
17년 전 조회 2,407
17년 전 조회 2,489
17년 전 조회 1,808
17년 전 조회 1,674
17년 전 조회 1,532
17년 전 조회 2,757
17년 전 조회 2,840
17년 전 조회 2,245
17년 전 조회 2,594
17년 전 조회 2,895
17년 전 조회 1,491
17년 전 조회 1,351
17년 전 조회 6,514
17년 전 조회 1,352
17년 전 조회 1,808
17년 전 조회 1,955
17년 전 조회 1,268
17년 전 조회 1,342
17년 전 조회 2,052
17년 전 조회 1,693
17년 전 조회 3,809
17년 전 조회 1,378
17년 전 조회 2,093
17년 전 조회 1,337
17년 전 조회 1,575
17년 전 조회 2,558
17년 전 조회 2,204
17년 전 조회 1,190
17년 전 조회 1,218
17년 전 조회 1,280
17년 전 조회 6,223
17년 전 조회 6,038
17년 전 조회 2,216
17년 전 조회 1,186
17년 전 조회 1,300
17년 전 조회 2,272
17년 전 조회 1,668
17년 전 조회 1,330
17년 전 조회 1,352
17년 전 조회 1,297
17년 전 조회 1,227
17년 전 조회 4,142
17년 전 조회 2,356
17년 전 조회 1,802
17년 전 조회 2,944
17년 전 조회 1,637
17년 전 조회 1,321
17년 전 조회 1,349
17년 전 조회 1,405
17년 전 조회 1,300
17년 전 조회 1,402
17년 전 조회 2,583
17년 전 조회 4,384
17년 전 조회 1,350
17년 전 조회 4,118
17년 전 조회 4,272
17년 전 조회 1,378
17년 전 조회 2,355
17년 전 조회 1,800
17년 전 조회 3,389
17년 전 조회 1,539
17년 전 조회 3,782
17년 전 조회 3,570
17년 전 조회 2,751
17년 전 조회 3,116
17년 전 조회 2,813
17년 전 조회 2,134
17년 전 조회 3,488
17년 전 조회 2,818