我遇到了我的jQuery驗證腳本的問題。jQuery驗證不驗證
你可以找到http://jsfiddle.net/R3wrn/1/
的jQuery代碼:
$(document).ready(function() {
$("#frmContact").validate({
rules: {
contact_name: "required",
contact_firstname: "required",
contact_email: {
required: true,
email: true
},
contact_company: "required",
contact_VAT: "required",
contact_Address: "required",
contact_ZIP: "required",
contact_city: "required",
contact_country: "required"
}
});
});
HTML:
<form id="frmContact" action="#" method="post" class="f2m contactForm">
<div class="inputgroup">
<label for="contact_name">Name</label>
<input type="text" id="contact_name" value="" />
</div>
<div class="inputgroup">
<label for="contact_firstname">First name</label>
<input type="text" id="contact_firstname" value="" />
</div>
<div class="inputgroup">
<label for="contact_email">Email</label>
<input type="text" id="contact_email" value="" />
</div>
<div class="inputgroup">
<label for="contact_name">Company</label>
<input type="text" id="contact_company" value="" class="required" />
</div>
<div class="inputgroup">
<label for="contact_VAT">VAT number</label>
<input type="text" id="contact_VAT" value="" class="required" />
</div>
<div class="inputgroup">
<label for="contact_Address">Address</label>
<input type="text" id="contact_Address" value="" />
</div>
<div class="inputgroup">
<label for="contact_ZIP">Postal code</label>
<input type="text" id="contact_ZIP" value="" />
</div>
<div class="inputgroup">
<label for="contact_city">City</label>
<input type="text" id="contact_city" value="" />
</div>
<div class="inputgroup">
<label for="contact_country">Country</label>
<select id="contact_country">
<option value="">---</option>
<option value="8b902045-d885-4777-86fb-e44788d842e3">België</option>
<option value="1a839cad-d0a0-449e-b376-96f120e78c9e">Duitsland</option>
<option value="bcabef32-78eb-4489-a90a-cfa42e525053">France</option>
<option value="788806bb-c3ec-4a42-a651-64e676065b7d">Griekenland</option>
<option value="542063ac-025b-44c5-8324-f36bde1c7989">Groot-Brittannië</option>
<option value="c5159342-0cbb-4f9d-b449-71d16e0953e0">Italië</option>
<option value="65c9621d-4f6a-45d4-9d8c-25d6e27432d3">Luxemburg</option>
<option value="14874203-02c2-4999-a0a5-aabcacf21530">Nederland</option>
<option value="135523df-5161-4c90-865c-cbf280569631">Noorwegen</option>
<option value="e0954d61-d0f3-498a-850f-33a54be040d5">Portugal</option>
<option value="ab0a9f35-206e-419b-9fb9-b8bbd51066cb">Spanje</option>
<option value="19766c79-51be-4094-95e5-6a981a452491">Zweden</option>
</select>
</div>
<div class="inputgroup">
<label for="contact_mobile">Mobile</label>
<input type="text" id="contact_mobile" value="" />
</div>
<div class="inputgroup">
<label for="contact_comments">Comments</label>
<textarea id="contact_comments" rows="10" cols="10"></textarea>
</div>
<div class="buttondiv">
<br />
<input type="submit" id="btnSendContact" class="button" value="Send your request" />
</div>
</form>
爲什麼僅在驗證companyname
?
我在ASP.NET MVC應用程序中或多或少有相同的代碼,但它不會驗證任何內容。
作品!側面問題:我如何防止「此字段是必需的」。字符串顯示? – JurgenStillaert
您可以像這樣設置消息選項: 消息:{contact_name:「」,contact_firstname:「」,..}。但我想有更好的方法來做到這一點.. –
http://www.meppum.com/2009/may/12/disabling-jquery-validation-error-messages/ – JurgenStillaert