bootstrap如何检测哪个按钮在“hidden_​​modal_bs”事件功能上关闭模态对话框? [英] bootstrap how to detect which button closed a modal dialog on 'hidden_modal_bs' event func?

查看:184
本文介绍了bootstrap如何检测哪个按钮在“hidden_​​modal_bs”事件功能上关闭模态对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主页上有一个欢迎类型的bootstrap-modal,显示三个按钮,每个按钮都应该加载不同的页面

I have a welcome type bootstrap-modal on homepage that shows three buttons, each one of them should load different pages

这是HTML的相关摘录

Here it is a relevant excerpt of the HTML

<div class="modal fade" id="welcomeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
  <div class="modal-dialog" >
    <div class="modal-content" ;">
      <div class="modal-header">
        <h3 class="modal-title" id="ModalLabel">Welcome to Here</h3>
      </div>
      <div class="modal-body" style='height: 90.5%;'>
        <span style="display:td;text-align;center;">Blah Blah BLah</span>
      </div>
      <div class="modal-footer">
        <div class="btn-group">
          <a id='taketour' class="btn btn-default btn-lg" data-dismiss="modal" ,aria-hidden="true" href="/tour">Take a tour</a>
          <a id='register' class="btn btn-default btn-lg" data-dismiss="modal" aria-hidden="true" href="/add">Register</a>
          <a id='login' class="btn btn-default btn-lg" data-dismiss="modal" aria-hidden="true" href="/login">Login</a>
        </div>
      </div>
    </div>
  </div>
</div

这里我的JS

$(window).load(function(){
    $('#welcomeModal').modal('show');
});

$('#welcomeModal').on('hidden.bs.modal', function (e) {
    if (e.id == 'taketour') {
        $(window).location=e.href;
    }
    if (e.id == 'login') {
        $('#welomeModal').remote='element-login';
    }
});

(注意:这个JS显然不行,只是我的最后一次尝试)

(Note: This JS obviously doesn't work. It's just my last attempt)

所以问题是:我如何找到从里面中的哪个按钮被隐藏在 hidden.modal.bs function?

So , the question is: How can I find which button has been pressed from inside the hidden.modal.bs function ?

推荐答案

而不是hidden.bs.modal,看看hide.bs.modal,在对话框关闭之前被触发。

Instead of hidden.bs.modal, have a look at hide.bs.modal, which is fired before the dialog is closed.

而不是看e,尝试查看document.activeElement(如document.activeElement.innerText或document.activeElement.id)。

And instead of looking at e, try looking at document.activeElement (like document.activeElement.innerText, or document.activeElement.id).

这篇关于bootstrap如何检测哪个按钮在“hidden_​​modal_bs”事件功能上关闭模态对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆