【问题标题】:jQuery-confirm with Tooltip带有工具提示的 jQuery 确认
【发布时间】:2020-08-07 21:17:59
【问题描述】:

我正在使用带有远程内容的jquery-confirm,并希望在返回内容中使用引导工具提示。除了工具提示之外,一切都按预期工作。

这是我的代码:

$(".div-link").click(function(){
  var $this = $(this),
    $cjstate = $this.data("cjstate");
  $.confirm({
    title: $cjstate.toUpperCase(),
    content: 'url:<?=site_url('main/remote_page/')?>'+$cjstate,
    contentLoaded: function(data, status, xhr){
      $('[data-toggle="tooltip"]').tooltip(); // TRIE INIT TOOLTIP HERE - DIDN'T WORK
    },
    onContentReady: function () {
      $('[data-toggle="tooltip"]').tooltip(); // TRIE INIT TOOLTIP HERE - DIDN'T WORK
    },
    columnClass: 'medium',
    buttons: {
      Close: function(){
        // close window
      }
    }
  });
});

我的 remote_page 看起来像这样。我已经注释掉了我尝试过的内容。

<!-- TRIED THIS AND IT DIDN'T WORK -->
<!-- <link rel="stylesheet" href="<?=site_url('assets/css/custom.css');?>"> -->
<table id="cjtbl" class="table table-sm">
  <thead>
    <tr>
      <th class="bg-primary">PowerBI Report</th>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($results as $item) :?>
        <tr>
          <td><a href="<?=$item['link'];?>" data-toggle="tooltip" data-placement="top" title="Tooltip on top" target="_blank"><?=$item['report'];?></a></td>
        </tr>
    <?php endforeach;?>
  </tbody>
</table>
<script type="text/javascript">
    //$('[data-toggle="tooltip"]').tooltip(); // TRIE INIT TOOLTIP HERE - DIDN'T WORK
</script>

我错过了什么?

【问题讨论】:

  • 我知道 onContentReady 在内容添加到 dom 时会被触发,但是您是否尝试过 onOpen 来代替,只是为了看看它是否有效?
  • 当然,此时我会尝试任何方法。感谢您的回复,不胜感激!
  • 遗憾的是 onOpen 没有用。

标签: jquery bootstrap-4 jquery-confirm


【解决方案1】:

问题与 jconfirm 的 z-index 样式属性有关。默认值高于tooltip。

为了解决这个问题,您可以将 jconfirm 值减小一点并将工具提示值设置为更高。

$(document).on('inserted.bs.tooltip', function () {
    $('.tooltip').css('z-index', 99999999);
});


$(".div-link").on('click', function (e) {
    var $this = $(this),
            $cjstate = $this.data("cjstate");
    $.confirm({
        title: $cjstate.toUpperCase(),
        content: 'url:https://gist.githubusercontent.com/gaetanoma/52b7700fd55d6530e62bc75bb031779a/raw/4fadb244611ef247b3f4583ae5cdd3f04feda1ed/popoveronjconfirm.txt',
        onContentReady: function () {
            this.$contentPane.closest('.jconfirm').css('z-index', 99999990);
            setTimeout(function () {
                $('[data-toggle="tooltip"]').tooltip(); // TRIE INIT TOOLTIP HERE - DIDN'T WORK
            }, 500);
        },
        columnClass: 'medium',
        buttons: {
            Close: function () {
                // close window
            }
        }
    });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js"></script>

<button class="div-link" data-cjstate="This is the state">Click me</button>

【讨论】:

  • 感谢您的建议,我会尝试并告诉您进展如何。干杯!
猜你喜欢
  • 2011-11-03
  • 1970-01-01
  • 1970-01-01
  • 2014-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多