我在1页上有2个表格,一个是主要表格,另一个是模态中的表格。第一个是asp.net引入的一个
<form name="aspnetForm" method="post" action="dataclass.aspx" id="aspnetForm">
在该表格关闭后,我带来了模态
</form>
<!-- edit modal -->
<div class="modal fade" id="editDataClassModal" tabindex="-3" role="dialog" aria-hidden="true" data-bind="with: selectedTag">
<div class="modal-dialog">
<form id="editDataClassForm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Edit Data Classification</h4>
</div>
<div class="modal-body">
<div class="form-horizontal">
<div class="form-group">
<label class="col-md-3 paddingTop3">
Classification:
</label>
<div class="col-md-9">
<input type="text" id="txtClassification" name="txtClassification" class="form-control" data-bind="value: copyname" />
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" id="btnCancelEdit" class="btn btn-primary btn-sm buttonsize" data-dismiss="modal">Cancel</button>
<button type="button" id="btnSaveEdit" class="btn btn-primary btn-sm buttonsize">Save</button>
<div class="marginTop10">
<span class="label-danger" id="lblErrorEdit" style="display: none;">An error occurred while saving this record.</span>
</div>
</div>
</div>
<!-- /.modal-content -->
</form>
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
问题是我无法获得第二个表单来验证,我的验证码是
$(document).on("click", "#btnSaveEdit", function () {
var form = $("#editDataClassForm");
form.validate();
if (form.valid()) {
// always goes in here
}
});
$("#editDataClassForm").validate({
rules: {
txtClassification: {
required: true,
minlength: 2
}
},
messages: {
txtClassification: {
minlength: "Classification must consist of at least 2 characters"
}
},
errorPlacement: function (label, element) {
label.addClass('errorText');
label.insertAfter(element);
},
wrapper: 'span'
});