首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单击next关闭前一个弹出窗口

问单击next关闭前一个弹出窗口
EN

Stack Overflow用户
提问于 2015-12-02 19:55:11
回答 1查看 682关注 0票数 0

我的页面上有很多弹出窗口,我想通过单击下一个弹出窗口来关闭上一个打开的弹出窗口。

它起作用了!但是,当我再次点击前一个波波弗,我必须点击两次!

我也希望通过点击外部关闭罂粟。

代码语言:javascript
复制
$('.triggerOverlay').popover({ 
html : true,
content: function() {
        var $this = $(this);
        var cont = $this.data('toggle');
        return $('#'+cont).html();
}});

关闭除当前以外的所有弹出窗口的下列代码

代码语言:javascript
复制
$('.triggerOverlay').on('click', function (e) {
    $('.triggerOverlay').not(this).popover('hide');
});

Fiddle

https://jsfiddle.net/yasirhaleem/43qfkjtb/

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-02 21:10:04

这应该能行。将click事件侦听器添加到文档中,并始终隐藏弹出框。

如果事件目标是带有弹出器的锚标记之一,则切换它。还将trigger属性添加到设置为manual的popover选项中。

​

代码语言:javascript
复制
$( document ).ready(function() {

  $('.triggerOverlay').popover({ 
    html : true,
    content: function() {
      var $this = $(this);
      var cont = $this.data('toggle');
      return $('#'+cont).html();
    },
    trigger: 'manual'
  });


  $(document).on('click', function (e) {
    // always hide them all.
    $('.triggerOverlay').popover('hide');
    // if e.target has a popover toggle it.
    if ($(e.target).hasClass('triggerOverlay')) {
      $(e.target).popover('toggle');
    }
  });

});
代码语言:javascript
复制
.customoverlay{display:none;}
代码语言:javascript
复制
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<a href="#" data-toggle="user-profile-overlay" class="triggerOverlay">button</a><br><br><br><br><br>
<div id="user-profile-overlay" class="customoverlay">content goes here</div>
<a href="#" data-toggle="user-profile-overlay1" class="triggerOverlay">button</a><br><br><br><br>
<div id="user-profile-overlay1" class="customoverlay">second content goes here</div>
<a href="#" data-toggle="user-profile-overlay2" class="triggerOverlay">button</a><br><br><br>
<div id="user-profile-overlay2" class="customoverlay">third content goes here</div>

​

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34051828

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档