자바스크립트

Script - 글자 수 제한 후 focus주기

yes or yes 2022. 5. 3. 15:54
반응형


1. 먼저 글을 작성할 수 있는 textarea를 만들어줍니다.

<textarea name="reply" id="reply" maxlength="20" placeholder="작성" ></textarea>



2. 글자수를 체크한 뒤 focus를 주고 return해서 더이상 진행되지 못하게 합니다.
if($('#reply').val().length < 10 || $('#reply').val().length > 100){
   alert('10자 이상 100자 이하로 작성 가능합니다.');
   $('#reply').focus();
   return;
}

반응형