1

嗨,我在一个表单中有两个表,它需要在 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>
4

1 回答 1

1

CSS classes as flags is a great way to emulate在纯 (X)HTML 标记中使用该概念。尤其是在使用 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 验证:表示组中至少有一个元素是必需的

jQuery Validate - 要求至少填写一个组中的一个字段

于 2011-12-07T05:24:53.480 回答