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,161
17년 전 조회 1,860
17년 전 조회 2,157
17년 전 조회 2,970
17년 전 조회 1,247
17년 전 조회 1,339
17년 전 조회 1,566
17년 전 조회 1,229
17년 전 조회 4,365
17년 전 조회 3,906
17년 전 조회 2,795
17년 전 조회 1,595
17년 전 조회 1,341
17년 전 조회 1,607
17년 전 조회 2,528
17년 전 조회 1,744
17년 전 조회 2,026
17년 전 조회 1,316
17년 전 조회 1,046
17년 전 조회 1,128
17년 전 조회 2,931
17년 전 조회 2,469
17년 전 조회 2,048
17년 전 조회 2,049
17년 전 조회 1,802
17년 전 조회 2,249
17년 전 조회 2,021
17년 전 조회 1,994
17년 전 조회 1,880
17년 전 조회 1,214
17년 전 조회 1,835
17년 전 조회 2,238
17년 전 조회 2,307
17년 전 조회 1,648
17년 전 조회 1,514
17년 전 조회 1,364
17년 전 조회 2,584
17년 전 조회 2,679
17년 전 조회 2,072
17년 전 조회 2,425
17년 전 조회 2,729
17년 전 조회 1,330
17년 전 조회 1,193
17년 전 조회 6,333
17년 전 조회 1,180
17년 전 조회 1,633
17년 전 조회 1,784
17년 전 조회 1,102
17년 전 조회 1,196
17년 전 조회 1,896
17년 전 조회 1,527
17년 전 조회 3,625
17년 전 조회 1,210
17년 전 조회 1,916
17년 전 조회 1,173
17년 전 조회 1,392
17년 전 조회 2,365
17년 전 조회 2,022
17년 전 조회 1,041
17년 전 조회 1,046
17년 전 조회 1,094
17년 전 조회 6,049
17년 전 조회 5,857
17년 전 조회 2,035
17년 전 조회 1,027
17년 전 조회 1,125
17년 전 조회 2,089
17년 전 조회 1,519
17년 전 조회 1,165
17년 전 조회 1,193
17년 전 조회 1,131
17년 전 조회 1,047
17년 전 조회 3,963
17년 전 조회 2,173
17년 전 조회 1,620
17년 전 조회 2,770
17년 전 조회 1,478
17년 전 조회 1,160
17년 전 조회 1,179
17년 전 조회 1,249
17년 전 조회 1,137
17년 전 조회 1,250
17년 전 조회 2,403
17년 전 조회 4,194
17년 전 조회 1,193
17년 전 조회 3,952
17년 전 조회 4,107
17년 전 조회 1,217
17년 전 조회 2,184
17년 전 조회 1,624
17년 전 조회 3,221
17년 전 조회 1,360
17년 전 조회 3,605
17년 전 조회 3,395
17년 전 조회 2,570
17년 전 조회 2,938
17년 전 조회 2,632
17년 전 조회 1,947
17년 전 조회 3,318
17년 전 조회 2,628
🐛 버그신고