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,222
17년 전 조회 1,923
17년 전 조회 2,240
17년 전 조회 3,049
17년 전 조회 1,325
17년 전 조회 1,404
17년 전 조회 1,635
17년 전 조회 1,311
17년 전 조회 4,440
17년 전 조회 3,980
17년 전 조회 2,866
17년 전 조회 1,673
17년 전 조회 1,408
17년 전 조회 1,670
17년 전 조회 2,600
17년 전 조회 1,816
17년 전 조회 2,099
17년 전 조회 1,379
17년 전 조회 1,116
17년 전 조회 1,197
17년 전 조회 2,996
17년 전 조회 2,542
17년 전 조회 2,122
17년 전 조회 2,124
17년 전 조회 1,870
17년 전 조회 2,320
17년 전 조회 2,087
17년 전 조회 2,056
17년 전 조회 1,941
17년 전 조회 1,278
17년 전 조회 1,894
17년 전 조회 2,300
17년 전 조회 2,386
17년 전 조회 1,710
17년 전 조회 1,580
17년 전 조회 1,436
17년 전 조회 2,654
17년 전 조회 2,743
17년 전 조회 2,133
17년 전 조회 2,490
17년 전 조회 2,798
17년 전 조회 1,392
17년 전 조회 1,250
17년 전 조회 6,401
17년 전 조회 1,249
17년 전 조회 1,706
17년 전 조회 1,842
17년 전 조회 1,167
17년 전 조회 1,264
17년 전 조회 1,957
17년 전 조회 1,594
17년 전 조회 3,698
17년 전 조회 1,282
17년 전 조회 1,980
17년 전 조회 1,237
17년 전 조회 1,465
17년 전 조회 2,431
17년 전 조회 2,089
17년 전 조회 1,101
17년 전 조회 1,116
17년 전 조회 1,174
17년 전 조회 6,117
17년 전 조회 5,917
17년 전 조회 2,100
17년 전 조회 1,097
17년 전 조회 1,197
17년 전 조회 2,147
17년 전 조회 1,578
17년 전 조회 1,226
17년 전 조회 1,254
17년 전 조회 1,192
17년 전 조회 1,122
17년 전 조회 4,021
17년 전 조회 2,237
17년 전 조회 1,685
17년 전 조회 2,829
17년 전 조회 1,537
17년 전 조회 1,220
17년 전 조회 1,249
17년 전 조회 1,311
17년 전 조회 1,198
17년 전 조회 1,305
17년 전 조회 2,469
17년 전 조회 4,257
17년 전 조회 1,261
17년 전 조회 4,014
17년 전 조회 4,167
17년 전 조회 1,282
17년 전 조회 2,246
17년 전 조회 1,688
17년 전 조회 3,291
17년 전 조회 1,429
17년 전 조회 3,668
17년 전 조회 3,465
17년 전 조회 2,625
17년 전 조회 2,998
17년 전 조회 2,697
17년 전 조회 2,017
17년 전 조회 3,375
17년 전 조회 2,702