필수항목 체크(text, textarea, select, checkbox, radio) > jquery

본문 바로가기

jquery

필수항목 체크(text, textarea, select, checkbox, radio)

작성일 18-03-20 09:15

페이지 정보

작성자서방님 조회 186회 댓글 0건

본문

text, textarea, select, checkbox, radio의 필수 선택항목을 체크한다.
체크할 항목에 class="required" 를 넣어주면 된다.
$(".btn_contents_ok").click(function(){
var requiredFlag = true;
$(".required,").each(function(){
if ( $(this).is(":text, textarea, select") && $(this).val().length < 1 ) {
alert("*은 필수 입력항목 입니다.");
$(this).focus();
requiredFlag = false;
return false;
}
else if ( $(this).is(":checkbox, :radio") && !$(this).parent().children(".required").is(":checked") ) {
alert("*은 필수 입력항목 입니다.");
$(this).focus();
requiredFlag = false;
return false;
};
});
if( requiredFlag == true && confirm("등록하시겠습니까?") ) {
location.href = "contents_add02.html";
return true;
}
});

댓글목록

등록된 댓글이 없습니다.

게시물 검색
Copyright © 서방님.kr All rights reserved.
PC 버전으로 보기