您好我有两个表需要在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>
答案 0 :(得分:1)
在普通(X)HTML标记中使用CSS classes as flags is a great way to emulate
这个概念。特别是在使用jQuery时,CSS“flags”是标记具有任意属性的元素的好方法,稍后可以使用简单的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