Bootstrap 模式 - 在“号召性用语"时关闭模式按钮被点击 [英] Bootstrap modal - close modal when "call to action" button is clicked

查看:28
本文介绍了Bootstrap 模式 - 在“号召性用语"时关闭模式按钮被点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模态中有一个外部链接,我希望在用户单击链接后隐藏模态.我该怎么做?

这是我的代码:

<div class="modal-body"><p>您需要在 google.com 上进行搜索.</p>

<div class="modal-footer"><a id="closemodal";href=https://www.google.com"类=btn btn-primary";target=_blank">启动google.com</a>

<script type="text/javascript">$('#closemodal').modal('隐藏');

解决方案

您需要将模态隐藏调用绑定到 onclick 事件.

假设您使用的是 jQuery,您可以使用:

$('#closemodal').click(function() {$('#modalwindow').modal('隐藏');});

还要确保在文档加载完成后绑定了点击事件:

$(function() {//将上面的代码放在这个块中});在此处输入代码

I have a external link inside my modal, and I want the modal to hide after the user has clicked on the link. How do I do that?

Here is my code:

<div class="modal hide fade" id="modalwindow">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3>Title</h3>
  </div>
  <div class="modal-body">
    <p>You need to do a search on google.com for that.</p>
  </div>
  <div class="modal-footer">
    <a id="closemodal" href="https://www.google.com" class="btn btn-primary" target="_blank">Launch google.com</a>
  </div>
</div>

<script type="text/javascript">
    $('#closemodal').modal('hide');
</script>

解决方案

You need to bind the modal hide call to the onclick event.

Assuming you are using jQuery you can do that with:

$('#closemodal').click(function() {
    $('#modalwindow').modal('hide');
});

Also make sure the click event is bound after the document has finished loading:

$(function() {
   // Place the above code inside this block
});
enter code here

这篇关于Bootstrap 模式 - 在“号召性用语"时关闭模式按钮被点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆