input 입력 여부 체크 입니다.

input 입력 여부 체크 입니다.

QA

input 입력 여부 체크 입니다.

본문


<input type="test" class="_check_inp_" title="이름"><br>
<input type="test" class="_check_inp_" title="전화번호"><br>
<input type="test" class="_check_inp_" title="이메일"><br>
<input type="test" class="_check_inp_" title="주소"><br>
 
<button type="button" class="btn">확인</button>

 

같은 클래스로  input이 있을때 

입력값이 없으면

(input title)을 입력하세요. 

라고 alert를 띄우고 싶습니다.

 

반복문을 통해 간단하게(?) 작성할 수 있을까요?

 

이 질문에 댓글 쓰기 :

답변 1


let _check=true;
$("._check_inp_").each(function(){
    if(!$.trim($(this).val()))
    {
        alert($(this).attr('title')+" 을 입력하세요.");
        $(this).focus();
        _check=false;
        return false;
    }
});
if(!_check) return false;

폼 전송시 유효성 검사하는 부분에 위 구문 추가하시면 될듯합니다. 

답변을 작성하시기 전에 로그인 해주세요.
전체 171
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT