我無法讓我的表單驗證下面作出迴應,除非我輸入文本和標籤到下一個。點擊不同的字段或點擊提交什麼也不做,我希望它能在所有情況下做出迴應。老實說,這是我第一次使用jQuery的任何比啓用或禁用類更復雜的東西,所以我可能在某處發生基本錯誤。但我無法弄清楚它是什麼。無法觸發jQuery驗證插件點擊
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script type="text/javascript">
//form validation
$(document).ready(function() {
$("#form").validate({
rules: {
organization: {
required: true,
minlength: 2,
},
firstname: {
required: true,
minlength: 2,
},
lastname: {
required: true,
minlength: 2,
},
email: {
required: true,
email: true,
},
phone: {
required: true,
minlength: 10,
number: true,
},
},
messages: {
organization: "Please enter a valid organization name",
firstname: "Please enter your first name",
lastname: "Please enter your last name",
email: "Please enter a valid email address",
phone: "Please enter a valid phone number",
},
});
});
</script>
</head>
<body>
<div id="form_container">
<div id="form_title">REQUEST INFO</div>
<form id="form" name="form_container" action="#">
<!-- fields -->
<input id="organization" type="text" name="organization" minlength="2" />
<input id="firstname" type="text" name="firstname" minlength="2" />
<input id="lastname" type="text" name="lastname" minlength="2" />
<input id="email" type="text" name="email" />
<input id="phone" type="text" name="phone" />
<!-- submit button -->
<input type="button" id="button" name="submit" type="submit" value="submit" >
</form>
</div>
</body>
</html>
哇。謝謝你指出!在我專注於jQuery的時候,我完全忘記了仔細檢查我的html屬性。還要感謝關於逗號的提示。 –
沒問題,有什麼機會可以接受它作爲答案? :) – mdellanoce
完成。對不起......第一次實際上在求助於stackoverflow。 –