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,226
17년 전 조회 1,925
17년 전 조회 2,247
17년 전 조회 3,053
17년 전 조회 1,331
17년 전 조회 1,409
17년 전 조회 1,642
17년 전 조회 1,315
17년 전 조회 4,443
17년 전 조회 3,989
17년 전 조회 2,871
17년 전 조회 1,675
17년 전 조회 1,412
17년 전 조회 1,679
17년 전 조회 2,607
17년 전 조회 1,819
17년 전 조회 2,106
17년 전 조회 1,383
17년 전 조회 1,122
17년 전 조회 1,203
17년 전 조회 3,006
17년 전 조회 2,547
17년 전 조회 2,127
17년 전 조회 2,133
17년 전 조회 1,877
17년 전 조회 2,330
17년 전 조회 2,092
17년 전 조회 2,062
17년 전 조회 1,950
17년 전 조회 1,282
17년 전 조회 1,899
17년 전 조회 2,308
17년 전 조회 2,397
17년 전 조회 1,716
17년 전 조회 1,586
17년 전 조회 1,442
17년 전 조회 2,659
17년 전 조회 2,749
17년 전 조회 2,146
17년 전 조회 2,495
17년 전 조회 2,800
17년 전 조회 1,400
17년 전 조회 1,256
17년 전 조회 6,406
17년 전 조회 1,256
17년 전 조회 1,709
17년 전 조회 1,849
17년 전 조회 1,174
17년 전 조회 1,268
17년 전 조회 1,961
17년 전 조회 1,599
17년 전 조회 3,707
17년 전 조회 1,287
17년 전 조회 1,988
17년 전 조회 1,244
17년 전 조회 1,471
17년 전 조회 2,439
17년 전 조회 2,097
17년 전 조회 1,108
17년 전 조회 1,120
17년 전 조회 1,176
17년 전 조회 6,123
17년 전 조회 5,925
17년 전 조회 2,112
17년 전 조회 1,101
17년 전 조회 1,203
17년 전 조회 2,154
17년 전 조회 1,582
17년 전 조회 1,235
17년 전 조회 1,259
17년 전 조회 1,194
17년 전 조회 1,130
17년 전 조회 4,031
17년 전 조회 2,246
17년 전 조회 1,692
17년 전 조회 2,838
17년 전 조회 1,543
17년 전 조회 1,224
17년 전 조회 1,254
17년 전 조회 1,316
17년 전 조회 1,201
17년 전 조회 1,310
17년 전 조회 2,478
17년 전 조회 4,266
17년 전 조회 1,264
17년 전 조회 4,018
17년 전 조회 4,173
17년 전 조회 1,287
17년 전 조회 2,251
17년 전 조회 1,693
17년 전 조회 3,298
17년 전 조회 1,431
17년 전 조회 3,677
17년 전 조회 3,474
17년 전 조회 2,633
17년 전 조회 3,004
17년 전 조회 2,705
17년 전 조회 2,023
17년 전 조회 3,383
17년 전 조회 2,708