Jquery - 表单验证,向错误消息添加 css 样式

Jquery - form validation, add css styles to the error messages

我正在尝试将 css 样式添加到使用 Jquery 验证显示的错误消息中。这些在消息下面。我是 Jquery 的新手 我尝试将 css class 添加到错误消息中但没有效果。


HTML表格


<form method="post" action="mail.php" id="contact-form">
                   <div class="form-group">
                    <label for="name">Name</label>
                    <input type="Text" class="form-control" name="name" id="name" placeholder="Enter Name">
                  </div>
                  <div class="form-group">
                    <label for="subject">Subject</label>
                    <input type="text" class="form-control" name="subject" id="subject" placeholder="Enter Subject">
                  </div>
                  <div class="form-group">
                    <label for="email">Email address</label>
                    <input type="email" class="form-control" name="email" id="email" placeholder="Enter Email">
                  </div>
                  <div class="form-group">
                    <label for="comment">Message</label>
                    <input type="text" class="form-control" name="comment" id="comment" placeholder="Enter Message">
                  </div> 

                  <button type="submit" value="submit"  name="submit" class="btn btn-default">Submit</button>
                </form>

Jquery


    <script type="text/javascript">
                 $('#contact-form').submit(function () {
                 $('#loadingimage').show();
                 $('#loadingtext').show();
                });
    </script>

    <script type="text/javascript">
        (function($,W,D)
        {
            var JQUERY4U = {};

            JQUERY4U.UTIL =
            {
                setupFormValidation: function()
                {
                    //form validation rules
                    $("#contact-form").validate({
                        rules: {
                            name: "required",
                            subject: "required",
                            email: {
                                required: true,
                                email: true
                            },
                            comment: "required"
                        },
                        messages: {
                            name: "Please enter your Name",
                            subject: "Please enter a Subject",
                            email: "Please enter a valid Email Address",
                            comment: "Please enter your Message",

                        },
                        submitHandler: function(form) {
                            form.submit();
                        }
                    });
                }
            }

            //when the dom has loaded setup form validation rules
            $(D).ready(function($) {
                JQUERY4U.UTIL.setupFormValidation();
            });

        })(jQuery, window, document);
        </script>

尝试添加 errorClass:'error',

$("#contact-form").validate({
                            rules: {
                                name: "required",
                                subject: "required",
                                errorClass:'error',
                                email: {
                                    required: true,
                                    email: true
                                },
                                comment: "required"
                            },
                            messages: {
                                name: "Please enter your Name",
                                subject: "Please enter a Subject",
                                email: "Please enter a valid Email Address",
                                comment: "Please enter your Message",

                            },
                            submitHandler: function(form) {
                                form.submit();
                            }
                        });