我想检查发布表单中的文本字段在使用jQuery发布之前是否为空。如果有的话,我想在文本区旁边显示错误信息。我点击按钮提交空白字段的信息,但没有消息显示。在发布之前,我需要这个检查功能。这是我所做的。检查空文本字段的显示错误消息
<!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