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

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

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

댓글 작성

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

로그인하기

게시글 목록

번호 제목
10853
10852
10850
28848
10849
28847
10846
28846
10845
28845
10844
28844
28843
10843
28842
10842
28841
10841
28840
28839
10840
10839
24791
24789
10836
28838
24788
24787
24786
28837
28834
10835
10834
정규표현식 수수료계산
28833
28829
10833
10831
10830
10829
28828
10828
10827
10823
10822
10821
10820
28822
10814
10812
10811
10810
10808
10804
10797
28821
10796
10795
10794
10792
10789
10785
10781
10780
28820
10776
10769
10766
10765
10758
28818
10754
10753
10750
28817
10749
10748
10747
10746
10740
10738
10735
10734
28812
10730
10726
10725
28811
10724
10723
10722
10721
10717
10716
10715
10713
10712
10711
10710
10709
10708