I m trying to use the jQuery Validate plugin on a form like below:
JS:
<script src="jquery-1.7.1.js" type="text/javascript"></script>
<script src="jquery.validate.js" type="text/javascript"></script>
<script>
function ValidateFields() {
$("#createProgramForm").validate({
rules: {
firstname: { required: true, minlength: 2 },
lastname: { required: true }
},
messages: {
firstname: { minlength: "Minimum 2 characters." },
lastname: { required: "Please enter a last name." }
}
});
if ($("#createProgramForm").valid()) {
alert("Form is valid");
}
}
</script>
传真:
<body>
<div id="page">
<form id="createProgramForm">
<p>
<label for="firstname">
First Name</label>
<input name="firstname" id="firstname" type="text" />
</p>
<p>
<label for="lastname">First Name</label>
<input name="lastname" id="lastname" type="text" />
</p>
<p>
<button onclick="ValidateFields();">Validate</button>
</p>
</form>
</div>
</body>
当我点击Validate时,验证错误的信息在田地旁边显示。 但是,一旦实地在时,错误信息就不再有效。 是否有任何人知道这种情况发生?