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,153
17년 전 조회 1,851
17년 전 조회 2,149
17년 전 조회 2,961
17년 전 조회 1,239
17년 전 조회 1,328
17년 전 조회 1,555
17년 전 조회 1,221
17년 전 조회 4,354
17년 전 조회 3,897
17년 전 조회 2,785
17년 전 조회 1,588
17년 전 조회 1,334
17년 전 조회 1,599
17년 전 조회 2,517
17년 전 조회 1,732
17년 전 조회 2,016
17년 전 조회 1,304
17년 전 조회 1,036
17년 전 조회 1,119
17년 전 조회 2,922
17년 전 조회 2,459
17년 전 조회 2,040
17년 전 조회 2,040
17년 전 조회 1,793
17년 전 조회 2,239
17년 전 조회 2,011
17년 전 조회 1,984
17년 전 조회 1,872
17년 전 조회 1,207
17년 전 조회 1,824
17년 전 조회 2,227
17년 전 조회 2,299
17년 전 조회 1,638
17년 전 조회 1,507
17년 전 조회 1,355
17년 전 조회 2,574
17년 전 조회 2,670
17년 전 조회 2,067
17년 전 조회 2,413
17년 전 조회 2,719
17년 전 조회 1,321
17년 전 조회 1,186
17년 전 조회 6,321
17년 전 조회 1,172
17년 전 조회 1,623
17년 전 조회 1,772
17년 전 조회 1,096
17년 전 조회 1,189
17년 전 조회 1,889
17년 전 조회 1,519
17년 전 조회 3,617
17년 전 조회 1,203
17년 전 조회 1,907
17년 전 조회 1,165
17년 전 조회 1,380
17년 전 조회 2,359
17년 전 조회 2,012
17년 전 조회 1,033
17년 전 조회 1,037
17년 전 조회 1,089
17년 전 조회 6,044
17년 전 조회 5,849
17년 전 조회 2,025
17년 전 조회 1,019
17년 전 조회 1,116
17년 전 조회 2,078
17년 전 조회 1,510
17년 전 조회 1,157
17년 전 조회 1,184
17년 전 조회 1,126
17년 전 조회 1,041
17년 전 조회 3,955
17년 전 조회 2,163
17년 전 조회 1,617
17년 전 조회 2,761
17년 전 조회 1,466
17년 전 조회 1,150
17년 전 조회 1,172
17년 전 조회 1,241
17년 전 조회 1,127
17년 전 조회 1,243
17년 전 조회 2,395
17년 전 조회 4,183
17년 전 조회 1,186
17년 전 조회 3,944
17년 전 조회 4,095
17년 전 조회 1,210
17년 전 조회 2,175
17년 전 조회 1,618
17년 전 조회 3,211
17년 전 조회 1,353
17년 전 조회 3,596
17년 전 조회 3,388
17년 전 조회 2,559
17년 전 조회 2,932
17년 전 조회 2,624
17년 전 조회 1,941
17년 전 조회 3,309
17년 전 조회 2,619
🐛 버그신고