펀스몬스터

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

· 19년 전 · 3597
<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>
|
댓글을 작성하시려면 로그인이 필요합니다.

퍼블리셔팁

퍼블리싱과 관련된 유용한 정보를 공유하세요. 질문은 상단의 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
HTML 19년 전 조회 3,769
HTML 19년 전 조회 2,842
HTML 19년 전 조회 3,438
HTML 19년 전 조회 8,691
HTML 19년 전 조회 2,630
HTML 19년 전 조회 3,063
HTML 19년 전 조회 5,468
HTML 19년 전 조회 3,022
HTML 19년 전 조회 2,927
HTML 19년 전 조회 3,531
HTML 19년 전 조회 3,290
HTML 19년 전 조회 3,268
HTML 19년 전 조회 5,169
HTML 19년 전 조회 3,727
HTML 19년 전 조회 3,598
HTML 19년 전 조회 3,988
HTML 19년 전 조회 3,916
HTML 19년 전 조회 5,377
HTML 19년 전 조회 3,721
HTML 19년 전 조회 4,160
HTML 19년 전 조회 3,612
HTML 19년 전 조회 4,975
HTML 19년 전 조회 3,082
HTML 19년 전 조회 3,424
HTML 19년 전 조회 3,324
HTML 19년 전 조회 5,055
HTML 19년 전 조회 6,443
HTML 19년 전 조회 5,400
HTML 19년 전 조회 4,752
HTML 19년 전 조회 3,532