TEXTAREA에서 엔터 개수와 줄바꿈 되는 개수를 체크
페이지 정보
작성자 서방님 댓글 0건 조회 205회 작성일 07-03-08 10:27본문
TEXTAREA에서 엔터 갯수와 줄바꿈 되는 갯수를 체크
다음과 같이 textarea의 rows,offsetHeight,clientHeight,scrollHeight 속성을 이용해 구하실 수 있습니다.
var tn = document.all.testname;
var borderH = (tn.offsetHeight - tn.clientHeight) / 2;
var lineC = (tn.scrollHeight - borderH) / ((tn.clientHeight - borderH) / tn.rows);
alert("라인수:" + lineC);
전체라인 수가 구해지므로 n의 갯수를 빼시면 textarea의 wrap line의 수가 구해집니다.
<form name="frm1">
<textarea name="testname" cols="30" rows="10"></textarea>
<input type="button" value="확인" onclick="checkEnter()">
<form>
<script language="javascript">
<!--
function checkEnter()
{
var tn = document.all.testname;
var borderH = (tn.offsetHeight - tn.clientHeight) / 2;
var lineC = (tn.scrollHeight - borderH) / ((tn.clientHeight - borderH) / tn.rows);
alert("라인수:" + lineC);
}
//-->
</script>
댓글목록
등록된 댓글이 없습니다.