LinkedNestBlog

textarea 확장, 축소

by jinwon

textarea 확장, 축소

: Enter, Backspace키의 사용에 따라 textarea의 rows를 조정한다.

- javascript 영역

 

 function actionKey(){ 
     if(event.keyCode==8){     // event.keyCode 8 : backspace(<-)
        unextendInsertArea();
     }else if(event.keyCode==13){   //event.keyCode 13 : Enter
        extendInsertArea();
     }
 }  
 // textarea 확장
 function extendInsertArea(){
      commentRows++;
      $("#comment").attr("rows", commentRows);  
 } 
 // textarea 축소
 function unextendInsertArea(){
      if(commentRows > 1){
         commentRows--;
         $("#comment").attr("rows", commentRows);
      }
 }

 

- jsp 영역

 <table>
     <tr>
         <td>
              <textarea id="comment" name="comment" rows="1" onKeyDown="actionKey()" style="overflow:hidden;"></textarea>
         </td>
     </tr>
 </table>

 

* 참고

:백스페이스의 이벤트로 onKeyPress는 동작하지 않는다.

 이유는.... 잘 모르겠다.ㅡ,.ㅡ;

 찾아봅시다.