텍스트 필드에 숫자 입력시 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>
댓글 1개
게시판 목록
퍼블리셔팁
질문은 상단의 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 377 | HTML | 15년 전 | 5023 | ||
| 376 | HTML | 16년 전 | 3122 | ||
| 375 | HTML | 16년 전 | 3558 | ||
| 374 | HTML | 16년 전 | 3495 | ||
| 373 | HTML | 16년 전 | 3596 | ||
| 372 | HTML |
|
16년 전 | 3311 | |
| 371 | HTML | 16년 전 | 4120 | ||
| 370 | HTML | 16년 전 | 3307 | ||
| 369 | HTML | 16년 전 | 3292 | ||
| 368 | HTML | 16년 전 | 3554 | ||
| 367 | HTML | 16년 전 | 4031 | ||
| 366 | HTML |
잠자리똥꾸멍
|
16년 전 | 3028 | |
| 365 | HTML | 16년 전 | 3690 | ||
| 364 | HTML | 16년 전 | 4620 | ||
| 363 | HTML | 16년 전 | 3207 | ||
| 362 | HTML | 16년 전 | 2977 | ||
| 361 | HTML | 16년 전 | 2467 | ||
| 360 | HTML |
|
16년 전 | 3203 | |
| 359 | HTML | 16년 전 | 5667 | ||
| 358 | HTML | 16년 전 | 3199 | ||
| 357 | HTML | 17년 전 | 6307 | ||
| 356 | HTML | 17년 전 | 6169 | ||
| 355 | HTML | 17년 전 | 4176 | ||
| 354 | HTML | 17년 전 | 3472 | ||
| 353 | HTML | 17년 전 | 2619 | ||
| 352 | HTML | 17년 전 | 3714 | ||
| 351 | HTML | 17년 전 | 3143 | ||
| 350 | HTML | 17년 전 | 5560 | ||
| 349 | HTML | 17년 전 | 4662 | ||
| 348 | HTML | 17년 전 | 3854 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기