Bootstrap工具提示中的图片

时间:2018-07-02 08:12:54

标签: jquery html css twitter-bootstrap bootstrap-4

我正在尝试在网站的某些页面上显示带有图像的工具提示。但是,以某种方式,当我尝试使用 bootstrap 中的工具提示时,仅显示图像的路径,而不显示工具提示。任何人都可以暗示一下,到底哪里出了问题?

$(function() {
  $('[data-toggle="tooltip"]').tooltip({
    html:true
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
    
<!-- Latest compiled and minified Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" />
    
<!-- Latest compiled Bootstrap JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>


<label class="checkbox">
  @{
    var imageSrc = Server.MapPath("~/Content/Images/1.jpg");
   }
  <a href="#" data-toogle="tooltip" title="<img src='@imageSrc'/>">
    Style no. 1
  </a>
</label>

2 个答案:

答案 0 :(得分:7)

修正拼写错误(data-toggle而不是data-toogle),一切都会正常进行:

$(function() {
  $('[data-toggle="tooltip"]').tooltip({
    html: true
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>

<!-- Latest compiled and minified Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" />

<!-- Latest compiled Bootstrap JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>


<label class="checkbox">
  <a href="#" data-toggle="tooltip" title="<img class='img-thumbnail' src='https://picsum.photos/200/100'/>">
    Style no. 1
  </a>
</label>

答案 1 :(得分:0)

尝试一下:

$('a[data-toggle="tooltip"]').tooltip({
    animated: 'fade',
    placement: 'bottom',
    html: true
});

<a data-toggle="tooltip" title="<img src='http://getbootstrap.com/apple-touch-icon.png'/>">
        <i class="icon-shopping-cart"></i>
    </a>

另外,请参考https://www.tutorialrepublic.com/faq/how-to-insert-image-inside-bootstrap-popover.php