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,163
17년 전 조회 1,861
17년 전 조회 2,157
17년 전 조회 2,970
17년 전 조회 1,247
17년 전 조회 1,340
17년 전 조회 1,566
17년 전 조회 1,230
17년 전 조회 4,365
17년 전 조회 3,907
17년 전 조회 2,796
17년 전 조회 1,595
17년 전 조회 1,341
17년 전 조회 1,609
17년 전 조회 2,528
17년 전 조회 1,744
17년 전 조회 2,026
17년 전 조회 1,316
17년 전 조회 1,046
17년 전 조회 1,129
17년 전 조회 2,931
17년 전 조회 2,469
17년 전 조회 2,048
17년 전 조회 2,049
17년 전 조회 1,802
17년 전 조회 2,250
17년 전 조회 2,021
17년 전 조회 1,995
17년 전 조회 1,881
17년 전 조회 1,214
17년 전 조회 1,835
17년 전 조회 2,238
17년 전 조회 2,308
17년 전 조회 1,648
17년 전 조회 1,515
17년 전 조회 1,364
17년 전 조회 2,585
17년 전 조회 2,679
17년 전 조회 2,072
17년 전 조회 2,425
17년 전 조회 2,729
17년 전 조회 1,330
17년 전 조회 1,193
17년 전 조회 6,334
17년 전 조회 1,180
17년 전 조회 1,633
17년 전 조회 1,784
17년 전 조회 1,103
17년 전 조회 1,197
17년 전 조회 1,897
17년 전 조회 1,527
17년 전 조회 3,626
17년 전 조회 1,210
17년 전 조회 1,917
17년 전 조회 1,173
17년 전 조회 1,392
17년 전 조회 2,366
17년 전 조회 2,023
17년 전 조회 1,041
17년 전 조회 1,046
17년 전 조회 1,094
17년 전 조회 6,049
17년 전 조회 5,858
17년 전 조회 2,035
17년 전 조회 1,028
17년 전 조회 1,125
17년 전 조회 2,090
17년 전 조회 1,519
17년 전 조회 1,165
17년 전 조회 1,193
17년 전 조회 1,131
17년 전 조회 1,048
17년 전 조회 3,963
17년 전 조회 2,174
17년 전 조회 1,620
17년 전 조회 2,771
17년 전 조회 1,478
17년 전 조회 1,160
17년 전 조회 1,179
17년 전 조회 1,249
17년 전 조회 1,137
17년 전 조회 1,251
17년 전 조회 2,403
17년 전 조회 4,195
17년 전 조회 1,194
17년 전 조회 3,954
17년 전 조회 4,107
17년 전 조회 1,217
17년 전 조회 2,185
17년 전 조회 1,624
17년 전 조회 3,221
17년 전 조회 1,361
17년 전 조회 3,605
17년 전 조회 3,397
17년 전 조회 2,570
17년 전 조회 2,939
17년 전 조회 2,632
17년 전 조회 1,947
17년 전 조회 3,318
17년 전 조회 2,628
🐛 버그신고