验证功能不起作用

时间:2014-06-20 06:58:43

标签: jquery asp.net

我无法打印错误信息请帮帮我我想我无法正常打电话  功能 请为我做全力帮助我是jquery的新手..

$(document).ready(function () {
$("form").submit(function () {
    $("#form1").validate({

        rules: {
            name: "required",
            password: "required",
            repassword: "required",
            email: {
                required: true,
                email: true
            },
            mobile: "required"
        },
        messages: {
            name: "Please specify your name",
            password: "Please specify your Password",
            repassword: "Please specify your Repassword",
            email: {
                required: "We need your email address to contact you",
                email: "Your email address must be in the format of name@domain.com"
            },
            mobile: "Please specify your Mobile Number"
        },
        showErrors: function (errorMap, errorList) {
            if (errorList.length) {
                $("span").html(errorList[0].message);
            }
        }
    });
});
});

这是我的前端代码我在表单提交上调用validate -----

<form id="form1" action="" method="post" runat="server">
<div>

    <asp:label ID="heading" runat="server" text="Validation Form"></asp:label>
    <span id="res"></span>
    <table>
        <tr>
            <td class="deslabel">
                <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="TextBox1" runat="server" CssClass="destext" name="name"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="deslabel">
                <asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="TextBox2" runat="server" CssClass="destext" name="password"></asp:TextBox>
            </td>

        </tr>
        <tr>
            <td class="deslabel">
                <asp:Label ID="Label3" runat="server" Text="ResetPassword"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="TextBox3" runat="server" CssClass="destext" name="repassword"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="deslabel">
                <asp:Label ID="Label4" runat="server" Text="Email"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="TextBox4" runat="server" CssClass="destext" name="email"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="deslabel">
                <asp:Label ID="Label5" runat="server" Text="Mobile"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="TextBox5" runat="server" CssClass="destext" name="mobile"></asp:TextBox>
            </td>
        </tr>
        <tr align="center">
            <td colspan="2">
                <asp:Button ID="Button1" runat="server" Text="Validate" CssClass="destext" />
            </td>
        </tr>


    </table>
</div>


</form>

1 个答案:

答案 0 :(得分:0)

您需要在加载时调用validate,而不是在提交时调用。如果您在提交表单时设置了验证,那就是&#39;来不及验证它。

$(document).ready(function() {
    $("#form1").validate({
        // Rest of your settings...
    });
});