我已經自定義了我的表單來驗證必填字段,但即使所有字段都填寫正確,它也不會提交。從我的理解,jquery.validate.min.js阻止它被提交。有誰知道爲什麼我的表單不提交?Jquery驗證表單不發帖
的代碼如下:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>
<link rel="stylesheet" href="http://jqueryvalidation.org/files/demo/site-demos.css">
</head>
<div>
<form id="myform" method="POST" action="">
<label for="fname">First Name *: </label>
<input id="fname" name="fname">
<br/>
<label for="lname">Last Name *: </label>
<input id="lname" name="lname">
<br/>
<label for="email">Email *: </label>
<input id="email" name="email">
<br/>
<label for="jtitle">Job Title *: </label>
<input id="jtitle" name="jtitle">
<br/>
<label for="orgname">Organization *: </label>
<input id="orgname" name="orgname">
<br/>
<label for="orgname">Describe Yourself *: </label>
<input id="desyourself" name="desyourself" type="hidden" value="123">
<select id="desyourself" name="desyourself">
<option value="">
Choose One... </option>
<option value="124">
Customer
</option>
<option value="125">
Partner
</option>
<option value="126">
Prospect
</option>
<option value="127">
Other
</option>
<option value="128">
Misc.
</option>
</select>
<br/>
<input type="submit" value="Validate!">
</form>
</div>
<script>
// avoids form submit
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$.validator.methods.email = function(value, element) {
return this.optional(element) || /^([\w-\.][email protected](?!gmail.com)(?!yahoo.com)(?!hotmail.com)([\w-]+\.)+[\w-]{2,4})?$/.test(value);
}
$("#myform").validate({
rules: {
fname: {
required: true,
minlength: 1,
maxlength: 30,
lettersonly: true
},
lname: {
required: true,
minlength: 1,
maxlength: 30,
lettersonly: true
},
email: {
required: true,
email: true
},
jtitle: {
required: true,
minlength: 1,
maxlength: 30
},
orgname: {
required: true,
minlength: 1,
maxlength: 30
},
desyourself: {
required: true,
}
}
});
</script>
控制檯中的任何Java腳本錯誤? –
_「爲什麼我的表單沒有提交?」_device''id'和'name'屬性在'input','select'元素上重複?請注意,'javascript'不是必須返回預期的結果;你可以使用'HTML5''required'屬性 – guest271314