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,207
17년 전 조회 1,907
17년 전 조회 2,208
17년 전 조회 3,027
17년 전 조회 1,306
17년 전 조회 1,395
17년 전 조회 1,609
17년 전 조회 1,279
17년 전 조회 4,416
17년 전 조회 3,951
17년 전 조회 2,845
17년 전 조회 1,650
17년 전 조회 1,382
17년 전 조회 1,655
17년 전 조회 2,575
17년 전 조회 1,784
17년 전 조회 2,078
17년 전 조회 1,359
17년 전 조회 1,097
17년 전 조회 1,175
17년 전 조회 2,975
17년 전 조회 2,519
17년 전 조회 2,096
17년 전 조회 2,102
17년 전 조회 1,839
17년 전 조회 2,300
17년 전 조회 2,069
17년 전 조회 2,035
17년 전 조회 1,924
17년 전 조회 1,262
17년 전 조회 1,876
17년 전 조회 2,275
17년 전 조회 2,364
17년 전 조회 1,692
17년 전 조회 1,558
17년 전 조회 1,408
17년 전 조회 2,627
17년 전 조회 2,725
17년 전 조회 2,119
17년 전 조회 2,463
17년 전 조회 2,775
17년 전 조회 1,364
17년 전 조회 1,230
17년 전 조회 6,378
17년 전 조회 1,229
17년 전 조회 1,681
17년 전 조회 1,820
17년 전 조회 1,148
17년 전 조회 1,243
17년 전 조회 1,942
17년 전 조회 1,568
17년 전 조회 3,668
17년 전 조회 1,265
17년 전 조회 1,951
17년 전 조회 1,218
17년 전 조회 1,440
17년 전 조회 2,411
17년 전 조회 2,065
17년 전 조회 1,081
17년 전 조회 1,090
17년 전 조회 1,145
17년 전 조회 6,090
17년 전 조회 5,896
17년 전 조회 2,084
17년 전 조회 1,067
17년 전 조회 1,174
17년 전 조회 2,125
17년 전 조회 1,562
17년 전 조회 1,207
17년 전 조회 1,233
17년 전 조회 1,169
17년 전 조회 1,102
17년 전 조회 4,008
17년 전 조회 2,216
17년 전 조회 1,666
17년 전 조회 2,814
17년 전 조회 1,516
17년 전 조회 1,199
17년 전 조회 1,228
17년 전 조회 1,292
17년 전 조회 1,176
17년 전 조회 1,291
17년 전 조회 2,445
17년 전 조회 4,243
17년 전 조회 1,237
17년 전 조회 3,990
17년 전 조회 4,141
17년 전 조회 1,263
17년 전 조회 2,228
17년 전 조회 1,669
17년 전 조회 3,261
17년 전 조회 1,407
17년 전 조회 3,646
17년 전 조회 3,443
17년 전 조회 2,610
17년 전 조회 2,981
17년 전 조회 2,673
17년 전 조회 1,995
17년 전 조회 3,357
17년 전 조회 2,674