jQuery验证未验证 [英] jQuery Validation doesn't validate

查看:80
本文介绍了jQuery验证未验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jQuery验证脚本有问题.

I'm having a problem with my jQuery Validation script.

您可以在 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&#235;</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&#235;</option>
            <option value="c5159342-0cbb-4f9d-b449-71d16e0953e0">Itali&#235;</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应用程序中,我或多或少都具有相同的代码,但是这里不会进行任何验证.

I have more or less the same code in a ASP.NET MVC application, but there it won't validate anything.

推荐答案

jQuery Validate插件使用name属性,而不是id.尝试将输入的id属性更改为name.

jQuery Validate plugin uses the name attribute, not the id. Try changing your inputs' id attribute to name.

这篇关于jQuery验证未验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆