2009년 11월 15일 일요일

TEXTAREA 자동 사이즈 조절

출처 나는 운명보다 살아가는 힘에 더 큰 존애를 느낀다. | 아설
원문 http://blog.naver.com/famlilia/100068519407
CCL

TEXTAREA 자동 사이즈 조절

 

<!--1. 아래 스크립트를 HEAD 부분에 복사해 넣으세요. -->
 
<script type="text/javascript">
<!--
 function countLines(strtocount, cols) {
  var hard_lines = 1;
  var last = 0;
  while ( true ) {
   last = strtocount.indexOf("\n", last+1);
   hard_lines ++;
   if ( last == -1 ) break;
  }
  var soft_lines = Math.round(strtocount.length / (cols-1));
  var hard = eval("hard_lines " + unescape("%3e") + "soft_lines;");
  if ( hard ) soft_lines = hard_lines;
  return soft_lines;
 }

 function cleanForm() {
  var the_form = document.forms[0];
  for ( var x in the_form ) {
   if ( ! the_form[x] ) continue;
   if( typeof the_form[x].rows != "number" ) continue;
   the_form[x].rows = countLines(the_form[x].value,the_form[x].cols) +1;
  }
  setTimeout("cleanForm();", 300);
 }

 function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
   window.onload = func;
  } else {
   window.onload = function() {
    if (oldonload) {
     oldonload();
    }
   func();
   }
  }
 }

 addLoadEvent(function() {
  cleanForm();
 });
//-->
</script>

<!--<BODY></BODY> 부분에 아래의 스크립트를 복사해 넣으세요-->
<form>
<textarea cols="40" rows="2" name="reason">글자수가 늘어나면 자동으로 폼사이지도 늘어납니다.
엔터키를 눌러도 늘어납니다.</textarea>
</form> 

 

아이프레임 자동으로 사이즈 조절 예제
<script type="text/javascript">
<!--
 function IframeResize(obj) {
  var ifrm = obj;
  var the_height = ifrm.contentWindow.document.body.scrollHeight;
  ifrm.style.height = the_height+40; 
 } 
//-->
</script>
<iframe width="800" height="700" frameborder="0" onload="IframeResize(this)" scrolling="no" src="Board/listStart.jsp" ></iframe>

아이프레임상에서 자식창에서 부모창으로 페이지 이동하기(top을 쓰면 됨 ㅋㅋ)

<script>
 alert("로긴해주세요");
 top.location.href="../../index2.jsp";
</script>

댓글 없음:

댓글 쓰기