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,504
17년 전 조회 2,192
17년 전 조회 2,531
17년 전 조회 3,338
17년 전 조회 1,622
17년 전 조회 1,691
17년 전 조회 1,930
17년 전 조회 1,596
17년 전 조회 4,734
17년 전 조회 4,259
17년 전 조회 3,185
17년 전 조회 1,948
17년 전 조회 1,689
17년 전 조회 1,965
17년 전 조회 2,895
17년 전 조회 2,096
17년 전 조회 2,375
17년 전 조회 1,674
17년 전 조회 1,413
17년 전 조회 1,495
17년 전 조회 3,268
17년 전 조회 2,851
17년 전 조회 2,402
17년 전 조회 2,416
17년 전 조회 2,178
17년 전 조회 2,607
17년 전 조회 2,398
17년 전 조회 2,340
17년 전 조회 2,248
17년 전 조회 1,555
17년 전 조회 2,185
17년 전 조회 2,610
17년 전 조회 2,684
17년 전 조회 2,014
17년 전 조회 1,850
17년 전 조회 1,724
17년 전 조회 2,944
17년 전 조회 3,031
17년 전 조회 2,435
17년 전 조회 2,787
17년 전 조회 3,084
17년 전 조회 1,681
17년 전 조회 1,519
17년 전 조회 6,716
17년 전 조회 1,536
17년 전 조회 1,987
17년 전 조회 2,144
17년 전 조회 1,464
17년 전 조회 1,545
17년 전 조회 2,236
17년 전 조회 1,886
17년 전 조회 4,004
17년 전 조회 1,567
17년 전 조회 2,265
17년 전 조회 1,531
17년 전 조회 1,753
17년 전 조회 2,735
17년 전 조회 2,399
17년 전 조회 1,390
17년 전 조회 1,394
17년 전 조회 1,453
17년 전 조회 6,417
17년 전 조회 6,228
17년 전 조회 2,401
17년 전 조회 1,391
17년 전 조회 1,513
17년 전 조회 2,455
17년 전 조회 1,857
17년 전 조회 1,523
17년 전 조회 1,536
17년 전 조회 1,467
17년 전 조회 1,427
17년 전 조회 4,342
17년 전 조회 2,560
17년 전 조회 1,985
17년 전 조회 3,126
17년 전 조회 1,819
17년 전 조회 1,511
17년 전 조회 1,550
17년 전 조회 1,600
17년 전 조회 1,489
17년 전 조회 1,592
17년 전 조회 2,782
17년 전 조회 4,597
17년 전 조회 1,536
17년 전 조회 4,295
17년 전 조회 4,469
17년 전 조회 1,582
17년 전 조회 2,556
17년 전 조회 1,990
17년 전 조회 3,597
17년 전 조회 1,735
17년 전 조회 4,001
17년 전 조회 3,776
17년 전 조회 2,956
17년 전 조회 3,322
17년 전 조회 3,027
17년 전 조회 2,335
17년 전 조회 3,683
17년 전 조회 3,019