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

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

· 19년 전 · 2329
<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>

댓글 작성

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

로그인하기

게시글 목록

번호 제목
10705
10698
10697
10693
10687
10683
10681
10680
10677
10671
10670
10666
10664
10658
10656
10653
10652
10651
10650
10649
10648
10646
10645
10642
28809
10641
10638
10637
10636
10635
28808
10634
10632
28807
28806
10631
10630
10629
28805
10627
10626
10625
28804
28803
10624
10623
28802
10622
10620
10619
10618
10616
10615
10613
10611
28799
10610
10608
28798
10604
28794
10602
10600
28793
10596
10595
10593
28792
28791
28790
10592
28789
28787
10591
10590
10589
28785
10588
10587
28783
10586
28782
10585
10574
10571
10570
28778
10568
10567
28777
10564
10562
10561
28776
10559
10558
28775
28774
10557
10556