如果返回false,如何在提交时关闭引导模式
How to close bootstrap modal on submit if return false?
大家好,我想问一下如果返回false,如何在提交时关闭引导模式?因为如果我在表单返回false时单击提交,我的模态将不会关闭。
这是我使用Jquery Validate:进行的验证
<script>
$(function() {
// Disable Enter Key on submit
$('#myform').keypress(function(event) {
if(event.which == 13 || event.keyCode == 13) {
event.preventDefault();
return false;
}
});
$.validator.addMethod("nameRegex", function(value, element) {
return this.optional(element) || /^[a-zA-Z's'.]+$/i.test(value);
}, "Please input alphabet only");
$('#myform').validate({
ignore: "",
rules: {
fname : {
required: true,
nameRegex: true
},
lname : {
required: true,
nameRegex: true
},
position : {
nameRegex: true
},
supervisor_name : {
required: true,
nameRegex: true
}
},
messages: {
fname: {
required: "This field is required",
nameRegex: "Please input alphabet only"
},
lname: {
required: "This field is required",
nameRegex: "Please input alphabet only"
},
position: {
nameRegex: "Please input alphabet only"
},
supervisor_name: {
required: "This field is required",
nameRegex: "Please input alphabet only"
}
},
errorPlacement: function (label, element) {
label.insertAfter(element);
}
});
});
</script>
这是我的表格
<form id="myform" role="form" style="width: 800px;" action="change_info.php" method="POST">
<div class="red">
<div><label for="atasan"><b>First Name</b></label> </div>
</div>
<input class="col-md-4 col-xs-4 form-control3" id="fname" type="text" name="fname" value="<?php echo $get_data['first_name'] ?>" autocomplete="off"><br>
<br>
<div class="red">
<div>
<label for="atasan"><b>Last Name</b></label>
</div>
</div>
<input class="col-md-4 col-xs-4 form-control3" id="lname" type="text" name="lname" value="<?php echo $get_data['last_name'] ?>" autocomplete="off"><br>
<br>
<div>
<label for="atasan"><b>Position</b></label>
</div>
<input class="col-md-4 col-xs-4 form-control3" id="atasan" type="text" name="position" value="<?php echo $get_data['position'] ?>" autocomplete="off"><br>
<br>
<div class="red">
<div>
<label for="atasan"><b>Supervisor Name</b></label>
</div>
</div>
<input class="col-md-4 col-xs-4 form-control3" id="atasan" type="text" name="supervisor_name" value="<?php echo $get_data['supervisor_name'] ?>" autocomplete="off"><br>
<br>
<button class="btn btn-primary" type="button" data-target="#myModal" data-toggle="modal">OK</button>
<!-- Modal START -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h3><b>Change Name</b></h3>
</div>
<div class="modal-body" style="float: center;">
<h3 style="text-align: center;" class="modal-title"><b>Are you sure?</b></h3>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-thumbs-up"></span> <b>Yes!</b></button>
<button class="btn btn-danger" data-dismiss="modal"><span class="glyphicon glyphicon-thumbs-down"></span><b>No!</b></button>
</div>
</div>
</div>
</div>
<!-- Modal END -->
</form>
// If the modal is showing toggle will hide it
$('#myModal').modal('toggle');
// If you want to make sure it hides even if not showing.
$('#myModal').modal('hide');
'#myModal将是您打开并希望关闭的引导模式的domElementId
相关文章:
- 如果返回false,如何在提交时关闭引导模式
- 提交表单后,模式窗口未关闭
- 如何防止引导模式关闭表单提交使用代码点火器
- 提交的启动模式对话框未显示id值
- 如何在通过 AJAX 提交后显示模式窗体
- 无法在提交模式弹出窗口时禁用 .btn 默认值
- 关闭模式而不提交列表器
- 由多个按钮提交的一个模式引导表单
- 在单击回车键并从引导模式窗口中点击提交按钮时提交表单数据
- 无法在提交时获取引导模式显示
- 防止引导模式在单击提交按钮时关闭
- 在表单提交时隐藏模式
- 防止引导模式窗口在提交表单时关闭
- 提交表单后,将引导模式显示为“谢谢”
- bootstrapValidator ajax 请求,防止在提交后关闭引导模式
- 在 Jquery - jTable 中创建/更新模式的字段末尾添加自定义按钮,如提交按钮
- 引导模式注册表验证并提交
- 在“模式”对话框中提交表单
- 以引导模式提交信用卡表格
- Bootstrap模式-提交不工作