jquery - 오류: Cannot read properties of undefined (reading 'length')

easyliving·2023년 2월 5일

ERROR 저장소

목록 보기
1/10

Cannot read properties of undefined (reading 'length')

let id=$("#id").val();
      
$(function(){
  $("#id").focusout(function(){
    if(id.length<1){
      alert("ID를 입력하셔야합니다.");
      return false;
    }
  });//focusout
});//function

	위의 경우 $("#id").val() 값에 데이터가 없다면
    undefined로 뜨고,
    그럼 그 값의 length는 측정이 불가능해진다.

/*수정코드 */	
$(function(){
   $("#id").focusout(function(){
     if($("#id").val().length<1){
       alert("ID를 입력하셔야합니다.");
       return false;
     }
   });//focusout
 });//function

	
profile
가끔져요

0개의 댓글