테스트 사이트 - 개발 중인 베타 버전입니다

textarea에 입력된 길이만큼 게이지로 표현

· 19년 전 · 2326
<script language="JavaScript">
<!--
function textCounter(field,counter,maxlimit,linecounter) {
var fieldWidth = parseInt(field.style.width);
var charcnt = field.value.length;

if(charcnt > maxlimit) {
field.value = field.value.substring(0, maxlimit);
} else {
var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
document.getElementById(counter).style.width = parseInt((fieldWidth*percentage)/100)+"px";
setcolor(document.getElementById(counter),percentage,"background-color");
}
}

function setcolor(obj,percentage,prop){
obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}

// 페이지 로드시 명령
textCounter(document.getElementById("maxcharfield"),"progressbar1",200);
//-->
</script>

<!--
textarea에서 onkeydown,onkeyup,onfocus의 명령의 설명

textCounter(this,1,2);

this : 현재 textarea의 name값과 같음
1 : 게이지가 보여질 부분의 id값
2 : textarea에 입력 가능한 최대 글자수

** textarea에서 가로크기는 꼭 style로 해야함 cols는 안됨..
//-->
<textarea style="width:300px" rows="5" name="maxcharfield" onKeyDown="textCounter(this,'progressbar1',200);" onKeyUp="textCounter(this,'progressbar1',200);" onFocus="textCounter(this,'progressbar1',200);">

</textarea>

<!-- 입력 길이를 표시하는 게이지 //-->
<div id="progressbar1" style="width:1px; height:2px; background-color:#DFDFFF;"></div><div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 16:57:14 JavaScript에서 이동 됨]</div>

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

게시글 목록

번호 제목
28772
10555
10554
10553
28770
28769
10552
10551
28768
10550
10549
10548
10547
28767
10546
10545
10544
28766
10541
10540
10538
10537
10535
10534
10533
10532
28760
10531
10530
28759
10527
10525
10523
10520
28758
28757
10519
10518
10517
10515
28756
10514
10512
10511
10510
10509
10508
10507
28755
28751
10506
10505
10504
10503
10499
10487
28748
10486
28747
10484
10483
10482
28746
10480
10476
10473
10472
28745
10460
10456
28739
10455
28738
10451
10448
10446
10445
10444
10442
10439
10408
10403
10400
10398
10397
10396
10391
10390
28733
10389
10383
10378
28732
10342
28731
10335
28730
28729
28727
10332