Bootstrap 3:如何使用 jQuery 关闭弹出窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21598602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 01:38:17  来源:igfitidea点击:

Bootstrap 3: How to close popup using jQuery?

jqueryhtmltwitter-bootstrap

提问by mridul

In my code there is two popup windows. first for login and second for reset password. The link to second popup is inside of login popup. I want to automatically close login popup when i click link forgot password.

在我的代码中有两个弹出窗口。第一个用于登录,第二个用于重置密码。第二个弹出窗口的链接位于登录弹出窗口内。当我点击链接忘记密码时,我想自动关闭登录弹出窗口。

<a href="#" data-toggle="modal" data-target=".loginform">Login</a>
<!- Login Popup start-->

<div id="login" class="modal fade loginform" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    ....
    <label>
        <input type="checkbox"><span style="font-size:12px;display:block;">Remember me</span>
    </label>
</div>
</div>
</div>


</div>
<div class="modal-footer">
    <a data-toggle="modal" data-target=".forgotpassword" href="#" style="float:left;font-size:14px;">Forgot Password</a>
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    <button type="button" class="btn btn-primary">Login</button>
</div>
</div>
<!-- /.modal-content -->
</div>
</div>


<!- popuplogin end-->
<!- Popup forgot password start-->

<div id="forgot" class="modal fade forgotpassword" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    .......
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Reset</button>
    </div>
</div>
<!-- /.modal-content -->
</div>
</div>


<!- popup end-->

Jsfiddle demo

Jsfiddle 演示

回答by yashhy

keep an id for forget password link and on click do $('#login').modal('hide');

保留一个忘记密码链接的 id 并点击执行 $('#login').modal('hide');

$("#forgotPass").click(function(){
       $('#login').modal('hide');
});

FIDDLE

小提琴

回答by Ivan Seidel

In this documentation: http://getbootstrap.com/javascript/#modals

在本文档中:http: //getbootstrap.com/javascript/#modals

Showing: $('#myModal').modal('show');

显示: $('#myModal').modal('show');

Hiding: $('#myModal').modal('hide');

隐藏: $('#myModal').modal('hide');