$(document).ready(function() {
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$("#myform").validate({
rules: {
mother_fname: {
require_from_group: [1, ".row1-group"]
},
mother_lname: {
require_from_group: [1, ".row1-group"]
},
mother_email: {
require_from_group: [1, ".row1-group"]
},
mother_phone: {
require_from_group: [1, ".row1-group"]
},
father_fname: {
require_from_group: [1, ".row2-group"]
},
father_lname: {
require_from_group: [1, ".row2-group"]
},
father_email: {
require_from_group: [1, ".row2-group"]
},
father_phone: {
require_from_group: [1, ".row2-group"]
},
gardian_fname: {
require_from_group: [1, ".row3-group"]
},
gardian_lname: {
require_from_group: [1, ".row3-group"]
},
gardian_email: {
require_from_group: [1, ".row3-group"]
},
gardian_phone: {
require_from_group: [1, ".row3-group"]
}
}
});
});
<link rel="stylesheet" href="https://jqueryvalidation.org/files/demo/site-demos.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/additional-methods.min.js"></script>
<form id="myform" class="form-inline" method="post">
<div class="form-group">
<input class="form-control row1-group" type="text" name="mother_fname" id="mother_fname" placeholder="Mother's First Name" />
</div>
<div class="form-group">
<input class="form-control row1-group" type="text" name="mother_lname" id="mother_lname" placeholder="Mother's Last Name" />
</div>
<div class="form-group">
<input class="form-control row1-group" type="text" name="mother_email" id="mother_email" placeholder="Mother's Email Address" />
</div>
<div class="form-group">
<input class="form-control row1-group" type="text" name="mother_phone" id="mother_phone" placeholder="Mother's Phone Number" />
</div>
<hr>
<div class="form-group">
<input class="form-control row2-group" type="text" name="father_fname" id="father_fname" placeholder="Father's First Name" />
</div>
<div class="form-group">
<input class="form-control row2-group" type="text" name="father_lname" id="father_lname" placeholder="Father's Last Name" />
</div>
<div class="form-group">
<input class="form-control row2-group" type="text" name="father_email" id="father_email" placeholder="Father's Email Address" />
</div>
<div class="form-group">
<input class="form-control row2-group" type="text" name="father_phone" id="father_phone" placeholder="Father's Phone Number" />
</div>
<hr>
<div class="form-group">
<input class="form-control row3-group" type="text" name="gardian_fname" id="gardian_fname" placeholder="Gardian's First Name" />
</div>
<div class="form-group">
<input class="form-control row3-group" type="text" name="gardian_lname" id="gardian_lname" placeholder="Gardian's Last Name" />
</div>
<div class="form-group">
<input class="form-control row3-group" type="text" name="gardian_email" id="gardian_email" placeholder="Gardian's Email Address" />
</div>
<div class="form-group">
<input class="form-control row3-group" type="text" name="gardian_phone" id="gardian_phone" placeholder="Gardian's Phone Number" />
</div>
<hr>
<input type="submit" class="btn btn-primary" name="add_details" id="add_details" value="Add Details" />
</form>
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$("#myform").validate({
rules: {
mother_fname: {
require_from_group: [1, ".row1-group"]
},
mother_lname: {
require_from_group: [1, ".row1-group"]
},
mother_email: {
require_from_group: [1, ".row1-group"]
},
mother_phone: {
require_from_group: [1, ".row1-group"]
},
father_fname: {
require_from_group: [1, ".row2-group"]
},
father_lname: {
require_from_group: [1, ".row2-group"]
},
father_email: {
require_from_group: [1, ".row2-group"]
},
father_phone: {
require_from_group: [1, ".row2-group"]
},
gardian_fname: {
require_from_group: [1, ".row3-group"]
},
gardian_lname: {
require_from_group: [1, ".row3-group"]
},
gardian_email: {
require_from_group: [1, ".row3-group"]
},
gardian_phone: {
require_from_group: [1, ".row3-group"]
}
}
});
<link href="https://jqueryvalidation.org/files/demo/site-demos.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/additional-methods.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<form id="myform" class="form-inline" method="post">
<div class="form-group">
<input class="form-control row1-group" type="text" name="mother_fname" id="mother_fname" placeholder="Mother's First Name" />
</div>
<div class="form-group">
<input class="form-control row1-group" type="text" name="mother_lname" id="mother_lname" placeholder="Mother's Last Name" />
</div>
<div class="form-group">
<input class="form-control row1-group" type="text" name="mother_email" id="mother_email" placeholder="Mother's Email Address" />
</div>
<div class="form-group">
<input class="form-control row1-group" type="text" name="mother_phone" id="mother_phone" placeholder="Mother's Phone Number" />
</div>
<hr>
<div class="form-group">
<input class="form-control row2-group" type="text" name="father_fname" id="father_fname" placeholder="Father's First Name" />
</div>
<div class="form-group">
<input class="form-control row2-group" type="text" name="father_lname" id="father_lname" placeholder="Father's Last Name" />
</div>
<div class="form-group">
<input class="form-control row2-group" type="text" name="father_email" id="father_email" placeholder="Father's Email Address" />
</div>
<div class="form-group">
<input class="form-control row2-group" type="text" name="father_phone" id="father_phone" placeholder="Father's Phone Number" />
</div>
<hr>
<div class="form-group">
<input class="form-control row3-group" type="text" name="gardian_fname" id="gardian_fname" placeholder="Gardian's First Name" />
</div>
<div class="form-group">
<input class="form-control row3-group" type="text" name="gardian_lname" id="gardian_lname" placeholder="Gardian's Last Name" />
</div>
<div class="form-group">
<input class="form-control row3-group" type="text" name="gardian_email" id="gardian_email" placeholder="Gardian's Email Address" />
</div>
<div class="form-group">
<input class="form-control row3-group" type="text" name="gardian_phone" id="gardian_phone" placeholder="Gardian's Phone Number" />
</div>
<hr>
<input type="submit" class="btn btn-primary" name="add_details" id="add_details" value="Add Details" />
</form>
请检查以下代码
<form id="myform" class="form-inline" method="post">
<div class="form-group">
<input class="form-control row1-group" type="text" name="mother_fname" id="mother_fname" placeholder="Mother's First Name" />
</div>
<div class="form-group">
<input class="form-control row1-group" type="text" name="mother_lname" id="mother_lname" placeholder="Mother's Last Name" />
</div>
<div class="form-group">
<input class="form-control row1-group" type="text" name="mother_email" id="mother_email" placeholder="Mother's Email Address" />
</div>
<div class="form-group">
<input class="form-control row1-group" type="text" name="mother_phone" id="mother_phone" placeholder="Mother's Phone Number" />
</div>
<hr>
<div class="form-group">
<input class="form-control row2-group" type="text" name="father_fname" id="father_fname" placeholder="Father's First Name" />
</div>
<div class="form-group">
<input class="form-control row2-group" type="text" name="father_lname" id="father_lname" placeholder="Father's Last Name" />
</div>
<div class="form-group">
<input class="form-control row2-group" type="text" name="father_email" id="father_email" placeholder="Father's Email Address" />
</div>
<div class="form-group">
<input class="form-control row2-group" type="text" name="father_phone" id="father_phone" placeholder="Father's Phone Number" />
</div>
<hr>
<div class="form-group">
<input class="form-control row3-group" type="text" name="gardian_fname" id="gardian_fname" placeholder="Gardian's First Name" />
</div>
<div class="form-group">
<input class="form-control row3-group" type="text" name="gardian_lname" id="gardian_lname" placeholder="Gardian's Last Name" />
</div>
<div class="form-group">
<input class="form-control row3-group" type="text" name="gardian_email" id="gardian_email" placeholder="Gardian's Email Address" />
</div>
<div class="form-group">
<input class="form-control row3-group" type="text" name="gardian_phone" id="gardian_phone" placeholder="Gardian's Phone Number" />
</div>
<hr>
<input type="submit" class="btn btn-primary" name="add_details" id="add_details" value="Add Details" />
</form>
<script type="text/javascript">
$(document).ready(function() {
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$("#myform").validate({
rules: {
mother_fname: {
require_from_group: [1, ".row1-group"]
},
mother_lname: {
require_from_group: [1, ".row1-group"]
},
mother_email: {
require_from_group: [1, ".row1-group"]
},
mother_phone: {
require_from_group: [1, ".row1-group"]
},
father_fname: {
require_from_group: [1, ".row2-group"]
},
father_lname: {
require_from_group: [1, ".row2-group"]
},
father_email: {
require_from_group: [1, ".row2-group"]
},
father_phone: {
require_from_group: [1, ".row2-group"]
},
gardian_fname: {
require_from_group: [1, ".row3-group"]
},
gardian_lname: {
require_from_group: [1, ".row3-group"]
},
gardian_email: {
require_from_group: [1, ".row3-group"]
},
gardian_phone: {
require_from_group: [1, ".row3-group"]
}
}
});
});
</script>