【问题标题】:jquery grouping concept in asp.netasp.net中的jquery分组概念
【发布时间】:2012-01-14 16:15:08
【问题描述】:

您好,我在一个表单中有两个表,它需要在 jquery 中单独验证它们。当我点击 submit1 时,它应该只验证 table1,当我点击 submit2 时,它应该只验证表 2。

现在它同时验证两个我需要单独的表验证

<html>
<head>
    <script type="text/javascript">

        $(document).ready(function() {

            $("#form1").validate({

                rules: {

                    <%= txtUserName.UniqueID %>: {minlength: 5, required: true},    

                    <%= txtPassword.UniqueID %>: {minlength: 5, required: true},

                    <%= txtURL.UniqueID %>: {required: true},
                 }, 

                messages: {

                    <%= txtUserName.UniqueID %>: {

                        required: "Plaese enter your name",    

                        minlength: "User name must be atleaet of 5 characters"
                    },

                    <%= txtPassword.UniqueID %>: { 

                        required: "Plaese enter your password",     

                        minlength: "Password must be atleaet of 5 characters"    
                    },

                    <%= txtURL.UniqueID %>:{ required: "Plaese enter Website URL",},
                }

            });

        });    
    </script>
</head>    
<body>    
    <form id="form1" runat="server">

        <table width="50%" cellpadding="2" cellspacing="4" style="border: solid 1px navy; background-color: #d5d5d5;">

---username--
--password--
--url----
submit1
        </table>


 <table width="50%" cellpadding="2" cellspacing="4" style="border: solid 1px navy; background-color: #d5d5d5;">

---Firstname--
--Lastname--

-Address----
submit2

        </table>    
    </form>
</body>

【问题讨论】:

    标签: jquery asp.net webforms grouping concept


    【解决方案1】:

    在纯 (X)HTML 标记中使用 CSS classes as flags is a great way to emulate 该概念。尤其是在使用 jQuery 时,CSS“标志”是标记具有任意属性的元素的好方法,以后使用简单的 DOM 选择器很容易找到。

    带有validationGroup 类的字段集,我们最终得到这个标记:

    <fieldset class="validationGroup">
      <legend>Returning customer?  Login here</legend>
     
      <!-- Username and Password labels and inputs here -->
    </fieldset>
    

    按照这个来完成实现:Emulate ASP.NET validation groups with jQuery validation

    参考链接:
    jQuery validation: Indicate that at least one element in a group is required

    jQuery Validate - require at least one field in a group to be filled

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-18
      • 1970-01-01
      • 1970-01-01
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-08
      相关资源
      最近更新 更多