JavaScript to Active Twitter Bootstrap Tooltips

后端 未结 4 1935
情话喂你
情话喂你 2021-02-20 08:47

I\'m playing around with Twitter Bootstrap\'s Tooltips, but am having problems since they moved away from Twipsy. The correect JavaScript is included in the page.

Let\'s

相关标签:
4条回答
  • 2021-02-20 09:21

    You need to explicitly run .tooltip() for all elements that have to have tooltip. For example, this will work:

    <span rel="tooltip" title="tooltip text">some text</span>
    ...
    <script src="/js/jquery.js"></script>
    <script src="/js/bootstrap.js"></script>
    <script type="text/javascript">
      $(document).ready(function () {
        $("[rel=tooltip]").tooltip();
      });
    </script>
    
    0 讨论(0)
  • 2021-02-20 09:24

    For your example it will just be:

    $('a').tooltip();
    

    but according to the documentation, you should use the title attribute, not data-original-title. That attribute is added by Bootstrap's tooltip code. Also there is no need for rel="tooltip".

    Your code should be:

    HTML:

    <a href="#" title="hello">hover on me</a>
    

    JS:

    $("a").tooltip(); // this will trigger a tooltip on all <a> elements
    
    0 讨论(0)
  • 2021-02-20 09:24

    In Bootstrap, We need to manually initialize Tooltips

    its mentioned in their Documentation also.

     <script type="text/javascript">
    $(function () {
        $("[data-toggle='tooltip']").tooltip();
    });</script>
    
    0 讨论(0)
  • 2021-02-20 09:33

    you need exactly to

      <script src="bootstrap-tooltip.js "></script>
      <script>
        $(function (){
    $('a').tooltip();
     });
    

    0 讨论(0)
提交回复
热议问题