简体   繁体   English

使用Bootstrap 3,如何将html添加到工具提示中?

[英]Using Bootstrap 3, how do you add html to a tooltip?

I have been having trouble getting HTML into a tooltip using bootstrap 3. I have scoured the internet and tried (seemingly) everything, but it's not working. 我在使用引导程序3将HTML引入工具提示时遇到了麻烦。我已经在Internet上进行搜索并尝试了(似乎)进行了所有操作,但均无法正常工作。 I will put my code below, but basically what's happening is when I hover over the link, it's generating a tooltip with no HTML, but it's also placing the same text onto the webpage itself. 我将代码放在下面,但是基本上发生的是,当我将鼠标悬停在链接上时,它会生成没有HTML的工具提示,但也会在网页本身上放置相同的文本。 When I leave the hover, the tooltip (with no html) dissappears, but the text on the webpage remains. 当我离开悬停时,工具提示(没有html)消失了,但是网页上的文本仍然保留。 Can anyone help? 有人可以帮忙吗? My code is below... The version of bootstrap (js and css) I am using is 3.3.7. 我的代码在下面...我正在使用的引导程序(js和css)的版本是3.3.7。 The version of jquery is 3.1.0 jQuery的版本是3.1.0

Thanks for the help. 谢谢您的帮助。 Also, I couldn't find "Bootstrap-3" for a tag, so I had to use twitter-bootstrap. 另外,我找不到标签的“ Bootstrap-3”,因此不得不使用twitter-bootstrap。 Sorry if that causes confusion, but the version of bootstrap I am using is listed in the question (3.3.7). 抱歉,这会引起混淆,但是问题(3.3.7)中列出了我使用的Bootstrap版本。

HTML Code HTML代码

    <link href="static/css/opendcs.css" rel="stylesheet">
<script src="static/js/jquery-3.1.0.min.js"></script> 
<script src="static/js/blah.js"></script> 
<form method=post enctype=multipart/form-data>
<legend class="legendFooter noBottomMargin noBorders">Upload Rating Table</legend>
<legend></legend>
  <div class="container blah">
    <div class="panel panel-default">
      <input type=file name=file>
    </div>
    <input class="btn btn-info" type=submit value=Upload>

    <a id="additionalInfoToolTip" href="#" data-html="true" data-toggle="tooltip"  data-placement="right" title="Here is a title" target="_blank">Additional Information</a>
  </div>
</form>

blah.js: blah.js:

$( document ).ready(function() {
    console.log( "Page is ready." );
    //$('#additionalInfoToolTip').tooltip();
    $('#additionalInfoToolTip').tooltip({
        selector: "a[rel=tooltip]"
      });
/*
  $('#additionalInfoToolTip').tooltip({
    selector: "a[rel=tooltip]"
  })

  $('.tooltip-demo.well').tooltip({
  selector: "a[rel=tooltip]"
})
*/
    $(function () {
        /*
      $('[data-toggle="tooltip"]').tooltip({
      })
      */
    })

});

Why not use a complete CSS tooltip 为什么不使用完整的CSS工具提示

 .wrap{ padding: 100px } .tooltip{ background: #fa0; display: inline-block; color: #fff; position: relative; padding: 5px 10px; border-radius: 20px; } /* Needed css */ .tooltip:hover::before, .tooltip:hover::after { opacity: 1; } .tooltip::after{ content: attr(data-title); /* <= dynamically title content */ z-index: 22; position: absolute; top: -35px; left: -27px; min-width: 60px; padding: 5px 10px; font-size: 70%; text-align: center; color: #fff; background: #000; border-radius: 20px; opacity: 0; } .tooltip::before{ /* For the arrow */ content: ''; width: 10px; height: 10px; background: #111; position: absolute; transform: rotate(45deg); top: -18px; left: 8px; opacity: 0; } 
 <div class="wrap"> <span class="tooltip" data-title="Tool tip text"> Main text </span> <span class="tooltip" data-title="Another Tool tip text"> AnotherMain text </span> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM