Jquery Validation插件:未显示自定义错误消息

时间:2011-09-13 12:52:42

标签: jquery

我正在使用jquery验证来验证表单的输入。但是,我已经指定了自定义消息,但在单击提交页面时仍显示常规消息。以下是表单的代码:我错过了什么或做错了:

 <script language="javascript" type="text/javascript">

        $(document).ready(function () {


                $("#emailForm").validate({ rules: {
                    FromMail: {
                        required: true,
                        email: true
                    }
                },
                    messages: {
                        FromMail: {
                            required: "Please enter From email address.",
                            email: "Please enter valid From Email address."
                        }
                    },

                    errorPlacement: function (error, element) {
                        alert("errorPlacement");
                        error.appendTo(element.next());
                    },
                    showErrors: function (errorMap, errorList) {
                        alert("showErrors");
                    }
                });

        });

        function sendMail()
        {
            $("#emailDialog").dialog({ modal: true,
                buttons: { "Send": function () {
                    //$("#FromMail").addClass("ui-state-error");
                    if ($("#emailForm").validate().form() == true) {
                        $.getJSON($("#emailForm").attr("action"),
                            $("#emailForm").serialize(),
                            function (data) {
                                alert(data);
                            });
                    }
                },
                    "Cancel": function () { $("#emailDialog").dialog("close"); }
                }
            });
          }


    </script>
}

<body>
<div id="emailDialog" title="Email" style="display:none">
<form id="emailForm" action="@Url.Action("SendMail", "Content")" method="get" >

        <div class="editor-label">
        <label for="FromMail">From Email</label>
    </div>
    <div class="editor-field">
        <input id="FromMail" name="FromMail" style="width:200px" class="required email" type="text" value="" />
        <span class="field-validation-valid" data-valmsg-for="FromMail" data-valmsg-replace="true"></span>
    </div>

    <div class="editor-label">
        <label for="ToEmailList">To Email Address</label>
    </div>
    <div class="editor-field">
        <textarea cols="20" id="ToEmailList" name="ToEmailList" rows="2"   class="required email" style="width:200px">
        </textarea>
        <span class="field-validation-valid" data-valmsg-for="ToEmailList" data-valmsg-replace="true"></span>
    </div>

                      

0 个答案:

没有答案