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,152
17년 전 조회 1,850
17년 전 조회 2,149
17년 전 조회 2,961
17년 전 조회 1,239
17년 전 조회 1,328
17년 전 조회 1,554
17년 전 조회 1,221
17년 전 조회 4,353
17년 전 조회 3,897
17년 전 조회 2,785
17년 전 조회 1,588
17년 전 조회 1,332
17년 전 조회 1,599
17년 전 조회 2,515
17년 전 조회 1,731
17년 전 조회 2,016
17년 전 조회 1,304
17년 전 조회 1,034
17년 전 조회 1,119
17년 전 조회 2,921
17년 전 조회 2,459
17년 전 조회 2,040
17년 전 조회 2,040
17년 전 조회 1,793
17년 전 조회 2,239
17년 전 조회 2,010
17년 전 조회 1,983
17년 전 조회 1,872
17년 전 조회 1,207
17년 전 조회 1,823
17년 전 조회 2,226
17년 전 조회 2,298
17년 전 조회 1,638
17년 전 조회 1,506
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,095
17년 전 조회 1,187
17년 전 조회 1,888
17년 전 조회 1,518
17년 전 조회 3,616
17년 전 조회 1,202
17년 전 조회 1,906
17년 전 조회 1,164
17년 전 조회 1,380
17년 전 조회 2,359
17년 전 조회 2,010
17년 전 조회 1,033
17년 전 조회 1,036
17년 전 조회 1,088
17년 전 조회 6,044
17년 전 조회 5,848
17년 전 조회 2,024
17년 전 조회 1,018
17년 전 조회 1,114
17년 전 조회 2,078
17년 전 조회 1,509
17년 전 조회 1,155
17년 전 조회 1,182
17년 전 조회 1,126
17년 전 조회 1,040
17년 전 조회 3,955
17년 전 조회 2,161
17년 전 조회 1,615
17년 전 조회 2,761
17년 전 조회 1,466
17년 전 조회 1,150
17년 전 조회 1,172
17년 전 조회 1,238
17년 전 조회 1,125
17년 전 조회 1,243
17년 전 조회 2,393
17년 전 조회 4,182
17년 전 조회 1,184
17년 전 조회 3,944
17년 전 조회 4,094
17년 전 조회 1,210
17년 전 조회 2,174
17년 전 조회 1,617
17년 전 조회 3,210
17년 전 조회 1,352
17년 전 조회 3,594
17년 전 조회 3,385
17년 전 조회 2,558
17년 전 조회 2,931
17년 전 조회 2,623
17년 전 조회 1,939
17년 전 조회 3,309
17년 전 조회 2,618
🐛 버그신고