根据需求我试图验证表单。如何验证表单内的输入并在表单外提交按钮
实际上,我在Bootbox模式对话框中传递表单输入元素,并在模态对话框中动态传递提交按钮。
当输入类型=提交时,它可以验证表单输入。但是没有提交按钮里面的形式,因为我在模态中传递它,它无法验证表单。 例如:
<form id="form_id">
Name:<input type="text" required>
<input type="submit" value="Submit">
</form>
$("#form_id").submit(function(e)){
//validation is ok
return false;
}
这是确定的,但是,现在 模态:
var data="<form id="form_id">
Name:<input type="text" required>
</form>"; //getting from server
$.ajax({
url : 'url',
type : 'get',
async : true,
data : data,
success : function(data) {
modalDialog = bootbox.dialog({
size : 'large',
title : "Title"
show : false,
message : data,
buttons : {
success: {
label : "Close window",
className : "btn-default",
callback : function() {
return false;
//after clicking submit button it should ask required if no data input,and stay in dialog as what happened previous scenario.But dialog is closed.
}
}
}
});
modalDialog.on('shown.bs.modal', function() {
});
modalDialog.modal('show');
}
});
您可以检查与'.checkValidity形式()':[触发HTML5表单验证(http://stackoverflow.com/questions/7548612/triggering-html5-form-validation) – Andreas