jquery验证不验证所有表单

时间:2015-10-03 23:58:22

标签: jquery jquery-validate

我使用jquery验证,除了1个字段外,一切正常。我在下面有以下jquery

$().ready(function() {
    $('#cForm').validate({
        rules: { 
            cFname: { required: true },
            cLname: { required: true },
            cEmail: { required: true },
            cMessage: { required: true }
        },
        messages: {
            cFname: { required: "Please enter your first name" },
            cLname: { required: "Please enter your last name" },
            cEmail: { required: "Please enter your email address", email: "Must be a valid email address" },
            cMessage: { required: "Please enter a message" }                    
        },
        submitHandler: function(form) {
           $("#cSubmit span").text("Processing...");
           $("#cSubmit").attr('btn-disabled', true);
           form.submit();
         },
        // Do not change code below
        errorPlacement : function(error, element) {
            error.insertAfter(element);
        }
    });
});

这是我的html标记

        <form id="cForm" name="cForm" method="post">
            <div class="row">
                <div class="col-sm-6" style="padding-right:5px;">
                    <input type="text" class="form-control" placeholder="Please enter your first name" id="cFname" name="cfname">
                </div>
                <div class="col-sm-6" style="padding-left:5px;">
                    <input type="text" class="form-control" placeholder="Please enter your last name" id="cLname" name="cLname">
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <input type="email" class="form-control" placeholder="Please enter your email address" id="cEmail" name="cEmail">
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <textarea class="form-control" rows="10" placeholder="Write your message here" name="cMessage" id="cMessage" required></textarea>
                </div>
            </div>
            <button  href="https://collabbro-bvcxtds.c9.io/app/" type="submit" class="btn btn-default" name="cSubmit" id="cSubmit" role="button">Submit</button>
        </form>

代码验证除cFname输入之外的所有字段,我不知道为什么。我尝试更改html中的idname属性,但似乎没有任何效果。我在俯瞰什么?感谢您帮助我成为更好的全栈开发人员:)

1 个答案:

答案 0 :(得分:0)

在我的name属性中发现了拼写错误。已将其更正为name="cFname"而不是name="cfname"