如果点击里面的按钮,关闭模态
Close modal if a button inside is clicked
我想做的是在bootstrap的模态对话框的帮助下进行单页表单切换。
我的问题是当我在模态对话框中单击按钮时,模态对话框不会关闭,但表单开关成功切换…有没有人知道如何使模态对话框关闭,如果我点击了模态中的任何按钮?
模式对话框的HTML:
<a data-toggle="modal" href="#myModal">Click me</a></li>
<div class="container">
<div class="row">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" id="show_first" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">First</button>
<button type="button" id="show_second" class="btn btn-info" data-dismiss="modal" aria-hidden="true">Second</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="myFirst">
<div class="row">
<center>
<h1>First Page</h1>
</center>
</div>
</div>
<div class="mySecond">
<div class="row">
<center>
<h1>Second Page</h1>
</center>
</div>
</div>
</div>
脚本:
<script type="text/javascript">
$(function(){
$('.myFirst').hide();
$('.mySecond').hide();
$('#show_first').click(function(){
$('.mySecond').hide();
$('.myFirst').show();
return false;
});
$('#show_second').click(function(){
$('.myFirst').hide();
$('.mySecond').show();
return false;
});
});
</script>
正如评论中所说,在bootstrap中,你可以调用.modal('hide')
来关闭你的模态窗口,所以你可以像这样添加它到你绑定的点击事件中:
$('#show_first').click(function(){
$('.mySecond').hide();
$('.myFirst').show();
$('.modal').modal('hide');
return false;
});
$('#show_second').click(function(){
$('.myFirst').hide();
$('.mySecond').show();
$('.modal').modal('hide');
return false;
});
相关文章:
- 如何使用jquery关闭模态窗口,通过模拟模态's关闭按钮
- Angular Js 尝试从主按钮回调动态更改模态文本并且不起作用
- 如何在单击/接受/确认按钮后不再显示模态
- 多个“;关闭“;模态上的按钮
- 如何在提交按钮上触发模态&重定向Rails
- 我可以点击一个带硒的模态上的按钮吗
- 当使用angular.js和ui.bootstrap时,从模态内部的按钮单击事件未触发
- 如何在模态内部单击按钮时调用函数
- ASP.net按钮单击时不使用Jquery模态对话框激发
- 我开发了一个api,我希望它重定向到其他php页面,并在我点击api文件中的按钮时弹出模态
- 如何在单击每个连续模态中的按钮时显示多个模态
- NG-模型似乎只在模态视图内的离子单选按钮上绑定一种方式
- JQuery 如何在按钮单击时启动模态框(对话框)
- 通过单击按钮以 mvc 形式触发模态弹出窗口
- java脚本中的非模态警报消息,由按钮激活
- 当按下当前模态上的按钮时,如何触发另一个模态
- 如何获取jquery和模态窗口的按钮ID
- 我怎么能阻止我的引导模态按钮从滚动页面
- MDL模态按钮适用于一张卡,但不适用于其他卡
- 第二个模态按钮不起作用