【问题标题】:Popover is not showing on first click after closing it关闭后第一次点击弹出框不显示
【发布时间】:2016-01-29 04:07:40
【问题描述】:

我正在处理this demo。我试图找出为什么弹出窗口在通过.close 按钮关闭后第一次单击时不起作用。

 $("#pop-One").popover({
        placement: 'right',
        html: 'true',
        title : '<span class="text-info" style=""><strong>Model Type</strong></span>'+
                '<button type="button"  class="btn btn-default close" onclick="$("#pop-One").popover("hide");">×</button>',
        content : '<p class="popup" style="color:#323232;"> \Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s,</p>'
    });
@import 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css';
@import 'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css';
body{padding:20px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="container">
<button type="button" class="btn btn-default" id="pop-One" data-toggle="popover"><i class="fa fa-question"></i></button>
</div>

不管什么原因,关闭按钮在这里不起作用。我已经看过this post,但那是另一种方法。

【问题讨论】:

标签: javascript jquery twitter-bootstrap-3 bootstrap-popover


【解决方案1】:
  <div id="timepickerDue" class="input-group date mytime activitydateblock" uib-popover-template="'myTooltipTemplate.html'" popover-trigger="'outsideClick'" popover-placement="bottom" popover-class="customClass" popover-is-open="isEnable"></div>
 <div uib-popover-template-popup="" uib-title="" content-exp="contentExp()" origin-scope="origScope" class="popover ng-scope ng-isolate-scope bottom customClass fade in" tooltip-animation-class="fade" uib-tooltip-classes="" ng-class="{ in: isOpen }" style="top: 125px; left: 363px;"><div class="arrow"></div>

以上是 Popover 的 HTML 标记。

为什么它在双击而不是单击时起作用的实际问题有点棘手。这背后的原因是 bootstrap 和 angular 需要元素点击事件来注册。

请使用以下代码在 ipod 中修复此问题。如果您打算使用非触控设备,您可以使用 $(document).on('click', function(e) 而不是 $(document).on('touchstart', function(e)

    $(document).on('touchstart', function(e) {
         if ($("div[uib-popover-template-popup='']").hasClass('popover ng-scope ng-isolate-scope bottom customClass fade in') && $(e.target).closest('div[class^="popover-content"]').length <= 0)
         angular.element('#timepickerDue').triggerHandler('click')
  });

【讨论】:

    【解决方案2】:

    不知道这是不是最好的解决方案,但它正在工作

      $("#pop-One").popover({
            placement: 'right',
            html: 'true',
            title : '<span class="text-info" style=""><strong>Model Type</strong></span>'+
                    '<button type="button"  class="btn btn-default close"\
         onclick="$(&quot;#pop-One&quot;).popover(&quot;hide&quot;);">×</button>',
            content : '<p class="popup" style="color:#323232;"> \Lorem Ipsum is simply dummy\ text of the printing and typesetting industry. Lorem Ipsum has been the industry standard\ dummy text ever since the 1500s,</p>'
      }).on('shown.bs.popover', function() {
        var popup = $(this);
        $(this).parent().find("div.popover .close").click(function() {
          popup.click();
        });
      });
    

    here the result of my efforts

    【讨论】:

    • 触发点击可能是要走的路。之前的问题是,当触发器设置为点击时,它被手动隐藏了。所以那里发生了一些疯狂的事情。虽然现在你不需要 ...popover('hide')。因为是点击触发器在起作用。
    • 我知道这很棘手,不是最好的方法,但也不是最坏的方法
    • 我使用您的解决方案解决了我的其他引导问题。这真的很有帮助......
    猜你喜欢
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-04
    相关资源
    最近更新 更多