본문 바로가기
프로그래밍/JAVA, JSP

TextArea Maxlength 길이 제한

by 착살의 숲 2013. 11. 13.
반응형
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2.   
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4. <head>  
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  
  6. <title>TextArea Maxlength</title>  
  7. </head>  
  8. <body>  
  9.   
  10. <script type="text/javascript">  
  11.   
  12. function isMaxlength(obj){  
  13.   var mlength = obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";  
  14.   if (obj.getAttribute && obj.value.length > mlength)  
  15.     obj.value = obj.value.substring(0,mlength);  
  16. }  
  17.   
  18. </script>  
  19. TextAreaの最大値を「20」に設定:<br />  
  20. <textarea maxlength="20" cols="40" rows="5" onkeyup="return isMaxlength(this)"></textarea>  
  21.   
  22. </body>  
  23. </html> 
반응형

댓글