【问题标题】:Close button of the bootstrap popover not working properly引导弹出窗口的关闭按钮无法正常工作
【发布时间】:2015-04-29 03:35:15
【问题描述】:

弹出框的关闭按钮有问题。第一次,我关闭弹出框很好,但是当我打开另一个并尝试关闭它时,它不再起作用了。

这里是弹出框的 JS:

$(function () {
  $('[data-toggle="popover"]').popover({
    "html": true,
    "title": '<span class="text-info"><strong>title</strong></span>'+
            '<button type="button" id="close" class="close" >&times;    </button>',
    "content": function(){
        var div_id =  "tmp-id-" + $.now();
        return details_in_popup($(this).data('url'), div_id);
    }


  }).on('shown.bs.popover', function(e){
  var popover = jQuery(this);
  $('.close').on('click', function(e){
    popover.popover('hide');
  });
 });
});

任何线索是什么导致了这个问题?

谢谢!

【问题讨论】:

  • $('.close').on('click', function(e){更改为$('body').on('click','.close', function(e){
  • 我试过了,它对我不起作用......
  • 但您的代码似乎正在我的 jsfiddle https://jsfiddle.net/5due81cv/... 上运行
  • 我删除的唯一代码是你的return details_in_popup($(this).data('url'), div_id);

标签: javascript jquery twitter-bootstrap popover


【解决方案1】:

第二次创建弹出框时,$('.close') 将获得两个元素。

如果想隐藏所有popop使用

$('[data-toggle="popover"]').popover('hide')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 2021-06-21
    • 2013-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多