<script>
function acrrCheck(a){
var txtEle = $(a).children().find('input[type=text]');
for(var i = 0; i < txtEle.length; i ++){
// console.log($(txtEle[i]).val());
if("" == $(txtEle[i]).val() || null == $(txtEle[i]).val()){
var ele_id = $(txtEle[i]).attr("id");
//console.log("id : " + ele_id);
showAlert(ele_id);
return false; //비어있으면 false 반환
}
}
return true;
}
function showAlert(ele_id){
$("#" + ele_id).focus();
}
$(document).on("click","input:submit",function(){
var result = acrrCheck(".person");
if(result==false){
alert("입력을 확인하세요.");
return false;
} else{
return true;//from action 진행
}
});
</script>
<form method='post' action='#'>
<table class ="person">
<tr>
<td>
이름: <input id="name" type="text" name ="name"/>
</td>
<td>
직업: <input id="job" type="text" name="job"/>
</td>
<td>
연봉: <input id="sal" name="sal" type="text"/>
</td>
<td>
부서: <input id="dept" name="dept" type="text"/>
</td>
<td>
<input id="dept" name="dept" type="submit"/>
</td>
</tr>
</table>
</form>