events - Bootstrap 如何检测哪个按钮关闭了 'hidden_modal_bs' 事件函数上的模式对话框?

标签 events twitter-bootstrap-3 bootstrap-modal

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

这是 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显然不起作用。这只是我的最后一次尝试)

所以,问题是:我怎样才能从 中找到哪个按钮被按下了?内 hidden.modal.bs功能?

最佳答案

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

与其看 e,不如试试看 document.activeElement (如 document.activeElement.innerTextdocument.activeElement.id )。

关于events - Bootstrap 如何检测哪个按钮关闭了 'hidden_modal_bs' 事件函数上的模式对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23169953/

相关文章:

html - 根据内容自动调整面板宽度

html - 更改引导插入符的颜色(悬停在第一个 "li"元素上)

javascript - 在服务器端提交消息后关闭模态弹出窗口

video - 如何在页面刷新时停止引导模态视频自动播放

jquery - 根据条件排除点击事件?

c# - 从 Protected Virtual Void 方法或直接引发事件有什么不同?

events - Bootstrap 3页面中的模态加载

javascript - 在有事件的div内容上触发事件

jquery - 如何使 Bootstrap 列具有相同的高度,然后管理内部元素的高度?

javascript - Google Map API - 本地图处于模态时,路线服务不会自动缩放