qq_25006515 2015-04-19 12:05 采纳率: 57.4%
浏览 2564

asp.net为什么在使用了模板页的子页中jquery.validate不能使用

如下是我写的代码,为什么在使用了模板页的子页中用validate就不行呢,完全不起作用required: true也不提示必须输入,如下是代码,该怎么解决呢?麻烦大神指教。另外ContentPlaceHolder1_Button1 的ontentPlaceHolder1_前缀用的应该没错,点按钮后 alert("aswqdq");是有效果的,就是rules 不起作用
母页代码

 <body>
    <form id="form1" runat="server">
    <div class="nav">
        <table class="table" style="width: 100%; height: 165px;">
            <tr>
                <td rowspan="1" class="auto-style1">
                    <br />
                    <a href="">英雄列表</a></td>
                <td rowspan="1" class="auto-style2">
                    <br />
                    <a href="">精美皮肤</a></td>
                <td rowspan="1"colspan="2" rowspan="3" >
                </td>
                <td rowspan="1" class="auto-style3">
                    <br />
                    <a href="">符文天赋</a></td>
                <td rowspan="1" class="auto-style4">
                    <br />
                    <a href="">关于我们</a></td>
            </tr>
        </table>        
     </div>
     <div class="logo">
        <a href="main.aspx"><img src="images/League_of_Legends_Logo_zh.png" style="height: 250px; width: 420px" /></a>
     </div>
    <div class="content">  
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>
    </form>

</body>
</html>

子页代码

 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <div style="height: 800px; background-color: #000000; opacity: 0.5; z-index: 1">
        fe </div>
    <div class="div6" style="background-color: transparent; border: 2px solid #FFFFFF; z-index: 3;">
        <table class="regist" style="top: 121px; left: 114px; height: 439px; width: 700px; border:1px solid #FFFFFF;">
            <tr>
                <td colspan="3" class="auto-style9">
                    <pre>                                                          <span style="font-family:楷体; font-weight: bolder; font-size: xx-large;">英雄去战斗</span></pre>
                </td>
            </tr>
            <tr>
                <td rowspan="9" style="width:55%">
                    <div style="position:absolute; top: 6px; left: 5px; height: 422px; width: 264px;">
                        <img src="images/琴女.jpg" style="height: 422px; width: 259px" /></div>
                </td>
                <td class="auto-style5">账号:</td>
                <td class="auto-style6"><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td class="auto-style5">密码:</td>
                <td class="auto-style6"><asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox></td>
            </tr>
            <tr>
                <td class="auto-style5">确认密码:</td>
                <td class="auto-style6"><asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox></td>
            </tr>
            <tr>
                <td class="auto-style5">昵称:</td>
                <td class="auto-style6"><asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td class="auto-style5">性别:</td>
                <td class="auto-style6">
                    &nbsp;&nbsp;
                    <asp:RadioButton ID="RadioButton1" runat="server" GroupName="sex" Text="男" />&nbsp; <asp:RadioButton ID="RadioButton2" runat="server" GroupName="sex" Text="女" /></td>
            </tr>
            <tr>
                <td class="auto-style5">身份证:</td>
                <td class="auto-style6"><asp:TextBox ID="TextBox5" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td class="auto-style5">电话:</td>
                <td class="auto-style6"><asp:TextBox ID="TextBox6" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td class="auto-style5">邮箱:</td>
                <td class="auto-style6"><asp:TextBox ID="TextBox7" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td  class="auto-style8">
                    &nbsp;</td>
                <td  class="auto-style7">
                   <asp:Button ID="Button1" runat="server" Text="注册" OnClick="Button1_Click" />&nbsp;&nbsp;
                    <asp:Button ID="Button2" runat="server" Text="重置" OnClick="Button2_Click" />
                </td>
            </tr>
        </table>
    </div>

   <script src="js/jquery-1.7.2.min.js"></script>
    <script src="js/validate-1.9/jquery.validate.min.js"  type="text/javascript"></script>
    <script src="js/validate-1.9/jquery.validate.messages_cn.js" type="text/javascript"></script>

    <script>
        $(function () {
            $("#ContentPlaceHolder1_Button1").click(function () {
                $("#form1").validate({

                    rules: {
                        ContentPlaceHolder1_TextBox1 : { required: true, minlength: 1,maxlength:10 },
                        ContentPlaceHolder1_TextBox2 : { required: true, minlength: 5 },
                        ContentPlaceHolder1_TextBox3 : { required: true, minlength: 5 },
                        ContentPlaceHolder1_TextBox4 : { required: true, minlength: 5 },
                        ContentPlaceHolder1_TextBox5 : { required: true, minlength: 5 },
                        ContentPlaceHolder1_TextBox6 : { required: true, minlength: 5 },
                        ContentPlaceHolder1_TextBox7 : { required: true, minlength: 5 }
                    }
                });
                alert("aswqdq");
            });
        });
    </script> 
</asp:Content>
  • 写回答

4条回答 默认 最新

  • 娃都会打酱油了 2015-04-19 12:18
    关注

    你这个是初始化,不是验证……
    具体看下面
    http://www.cnblogs.com/hejunrex/archive/2011/11/17/2252193.html

    评论

报告相同问题?

悬赏问题

  • ¥15 luckysheet
  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题