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,906
17년 전 조회 2,208
17년 전 조회 3,027
17년 전 조회 1,301
17년 전 조회 1,394
17년 전 조회 1,609
17년 전 조회 1,279
17년 전 조회 4,416
17년 전 조회 3,950
17년 전 조회 2,845
17년 전 조회 1,648
17년 전 조회 1,381
17년 전 조회 1,655
17년 전 조회 2,575
17년 전 조회 1,783
17년 전 조회 2,078
17년 전 조회 1,358
17년 전 조회 1,096
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,259
17년 전 조회 1,876
17년 전 조회 2,274
17년 전 조회 2,364
17년 전 조회 1,692
17년 전 조회 1,555
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,227
17년 전 조회 1,681
17년 전 조회 1,820
17년 전 조회 1,147
17년 전 조회 1,242
17년 전 조회 1,941
17년 전 조회 1,566
17년 전 조회 3,668
17년 전 조회 1,262
17년 전 조회 1,951
17년 전 조회 1,217
17년 전 조회 1,438
17년 전 조회 2,411
17년 전 조회 2,065
17년 전 조회 1,080
17년 전 조회 1,089
17년 전 조회 1,145
17년 전 조회 6,090
17년 전 조회 5,896
17년 전 조회 2,083
17년 전 조회 1,067
17년 전 조회 1,174
17년 전 조회 2,125
17년 전 조회 1,561
17년 전 조회 1,207
17년 전 조회 1,232
17년 전 조회 1,168
17년 전 조회 1,102
17년 전 조회 4,008
17년 전 조회 2,215
17년 전 조회 1,666
17년 전 조회 2,814
17년 전 조회 1,513
17년 전 조회 1,199
17년 전 조회 1,228
17년 전 조회 1,291
17년 전 조회 1,176
17년 전 조회 1,289
17년 전 조회 2,445
17년 전 조회 4,243
17년 전 조회 1,236
17년 전 조회 3,990
17년 전 조회 4,141
17년 전 조회 1,262
17년 전 조회 2,227
17년 전 조회 1,668
17년 전 조회 3,261
17년 전 조회 1,406
17년 전 조회 3,646
17년 전 조회 3,443
17년 전 조회 2,610
17년 전 조회 2,981
17년 전 조회 2,673
17년 전 조회 1,995
17년 전 조회 3,357
17년 전 조회 2,674