이 블로그 검색

2016년 9월 26일 월요일

대충 갔다 쓰려고 만든 jquery 유효성 검사

$("#regBtn").click(function(){
var ckd = 0;
$("input[type=text], select").each(function(){
if ($(this).attr("msg") && !$(this).val()) {
alert($(this).attr("msg"));
$(this).focus();
ckd = 1;
return false;
}
})
if (ckd == 0) {
$("input[type=checkbox]").each(function(){
if (!$(this+":checked").val() && $(this).attr("msg") && !$("input[name='"+$(this).attr("andbox")+"']:checked").val()) {
alert($(this).attr("msg"));
$(this).focus();
ckd = 1;
return false;
}
})
}
if (ckd == 1) {return false;}else{$("#frm").submit();}
})