events – bootstrap如何检测哪个按钮关闭’hidden_​​modal_bs’事件func上的模态对话框?

前端之家收集整理的这篇文章主要介绍了events – bootstrap如何检测哪个按钮关闭’hidden_​​modal_bs’事件func上的模态对话框?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在主页上有一个欢迎类型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.innerText或document.activeElement.id).

原文链接:https://www.f2er.com/bootstrap/233909.html

猜你在找的Bootstrap相关文章