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,158
17년 전 조회 1,858
17년 전 조회 2,152
17년 전 조회 2,966
17년 전 조회 1,245
17년 전 조회 1,334
17년 전 조회 1,564
17년 전 조회 1,227
17년 전 조회 4,361
17년 전 조회 3,905
17년 전 조회 2,792
17년 전 조회 1,593
17년 전 조회 1,337
17년 전 조회 1,606
17년 전 조회 2,524
17년 전 조회 1,741
17년 전 조회 2,024
17년 전 조회 1,313
17년 전 조회 1,041
17년 전 조회 1,126
17년 전 조회 2,928
17년 전 조회 2,466
17년 전 조회 2,047
17년 전 조회 2,046
17년 전 조회 1,801
17년 전 조회 2,246
17년 전 조회 2,017
17년 전 조회 1,990
17년 전 조회 1,878
17년 전 조회 1,212
17년 전 조회 1,831
17년 전 조회 2,233
17년 전 조회 2,305
17년 전 조회 1,644
17년 전 조회 1,511
17년 전 조회 1,362
17년 전 조회 2,579
17년 전 조회 2,675
17년 전 조회 2,069
17년 전 조회 2,419
17년 전 조회 2,724
17년 전 조회 1,325
17년 전 조회 1,192
17년 전 조회 6,329
17년 전 조회 1,179
17년 전 조회 1,629
17년 전 조회 1,781
17년 전 조회 1,101
17년 전 조회 1,192
17년 전 조회 1,895
17년 전 조회 1,523
17년 전 조회 3,622
17년 전 조회 1,208
17년 전 조회 1,915
17년 전 조회 1,170
17년 전 조회 1,388
17년 전 조회 2,362
17년 전 조회 2,017
17년 전 조회 1,039
17년 전 조회 1,040
17년 전 조회 1,092
17년 전 조회 6,048
17년 전 조회 5,855
17년 전 조회 2,032
17년 전 조회 1,024
17년 전 조회 1,123
17년 전 조회 2,084
17년 전 조회 1,516
17년 전 조회 1,161
17년 전 조회 1,189
17년 전 조회 1,130
17년 전 조회 1,045
17년 전 조회 3,963
17년 전 조회 2,172
17년 전 조회 1,620
17년 전 조회 2,769
17년 전 조회 1,472
17년 전 조회 1,156
17년 전 조회 1,176
17년 전 조회 1,247
17년 전 조회 1,133
17년 전 조회 1,247
17년 전 조회 2,401
17년 전 조회 4,189
17년 전 조회 1,190
17년 전 조회 3,950
17년 전 조회 4,101
17년 전 조회 1,213
17년 전 조회 2,181
17년 전 조회 1,622
17년 전 조회 3,216
17년 전 조회 1,357
17년 전 조회 3,600
17년 전 조회 3,393
17년 전 조회 2,566
17년 전 조회 2,938
17년 전 조회 2,628
17년 전 조회 1,946
17년 전 조회 3,315
17년 전 조회 2,627
🐛 버그신고