Jquery表单验证无效

时间:2015-04-16 03:11:42

标签: javascript jquery validation jquery-plugins

请帮助我,我是asp.net的新手,希望创建一个带有表单验证的简单页面。

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
<script type="text/javascript">

    $(document).ready(function () {
      $("#Form1").validate({
        rules: {
                UserName: "required"

            },
            messages: {
                UserName: "Enter your firstname"
            }
         });

    });


</script>

Login.aspx Page

        登录     

<p>
    Please enter your username and password.
    <asp:HyperLink ID="RegisterHyperLink" runat="server" EnableViewState="false">Register</asp:HyperLink> if you don't have an account.

</p>
<asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false">
    <LayoutTemplate>
        <span class="failureNotification">
            <asp:Literal ID="FailureText" runat="server"></asp:Literal>
        </span>

        <div class="accountInfo">
            <fieldset class="login">
                <legend>Account Information</legend>
                <p>
                    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>
                    <asp:TextBox ID="UserName" runat="server" CausesValidation="True" ClientIDMode="Static" ></asp:TextBox>

                </p>
                <p>
                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                    <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
                </p>
                <p>
                    <asp:CheckBox ID="RememberMe" runat="server"/>
                    <asp:Label ID="RememberMeLabel" runat="server" AssociatedControlID="RememberMe" CssClass="inline">Keep me logged in</asp:Label>
                </p>

            </fieldset>
            <p class="submitButton">
                <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In"/>
            </p>
        </div>
    </LayoutTemplate>
</asp:Login>

上面显示的是我在母版页上写的部分代码。

没有显示错误,但遗憾的是脚本无效。

1 个答案:

答案 0 :(得分:0)

我不知道脚本应该是asp:login control。

&#34;&lt;%=((TextBox)LoginUser.FindControl(&#34; UserName&#34;))。UniqueID%&gt;&#34;

对不起家伙,在我错过我的HTML代码之前:(