jquery를 사용하여 게시하기 전에 게시 양식의 텍스트 필드가 비어 있는지 확인하고 싶습니다. 있다면, 텍스트 영역 바로 옆에 오류 메시지를 표시하고 싶습니다. 빈 필드가있는 정보를 제출하려면 버튼을 클릭하지만 메시지가 표시되지 않습니다. 게시가 수행되기 전에이 체크 기능이 필요합니다. 여기 내가 한 일이있다. 빈 텍스트 필드에 대한 표시 오류 메시지 확인
if(this.val()=="")
이 여야
<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.7.1.min.js"></script>
<script>
function ValidateForm()
{
$(document).ready(function(
{
$("#personID").each(function()
{
if(this.val()=="")
{
$("#error_msg").html("Field needs filling");
}
}
}
));
}
</script>
</head>
<body>
<form action="action.php" method="post" id="personID">
First Name: <input type="text" name="first"><span id="error_msg"></span></br>
Last Name: <input type="text" name="last"><span id="error_msg"></span></br>
Phone: <input type="text" name="phone"><span id="error_msg"></span></br>
Mobile: <input type="text" name="mobile"></br>
Position: <input type="text" name "pos"><span id="error_msg"></span></br>
<input type="button" value="Insert" onclick="ValidateForm">
</form>
</body>
</html>
그리고 귀하의 질문은 무엇입니까? – cambraca