Bootstrap popover is not working

前端 未结 3 947
野性不改
野性不改 2021-02-06 22:41

The bootstrap popover is not showing up my page

Here is my HTML:

相关标签:
3条回答
  • 2021-02-06 23:11

    Although the accepted answer is fine, when dealing with popovers, please be careful of situations with double initialization as well (Fiddle example). The below JavaScript will fail.

    <br/>
    <br/>
    <a href="#" id="firstButton" class="btn btn-primary" rel="popover" data-message="Message">Click Me (Working)</a>
    <br/>
    <br/>
    <a href="#" id="secondButton" class="btn btn-primary" rel="popover" data-message="Message">Click Me (Failing)</a>
    

    If you double-initialize and your popover uses values that may change or custom content, etc., you will be in a world of hurt:

    $(function () {
        $('#firstButton').popover({
          container: "body",
          html: true,
          content: function () {
            return '<div class="popover-message">' + $(this).data("message") + '</div>';
          }
        });
        $('#secondButton').popover(); // <-- The first initializer does this, which causes the next one to fail on the next line.
        $('#secondButton').popover({
          container: "body",
          html: true,
          content: function () {
            return '<div class="popover-message">' + $(this).data("message") + '</div>';
          }
        });
    });
    
    0 讨论(0)
  • 2021-02-06 23:14

    One robust solution is Writing script tag of jquery, popper before bootstrap javascript.

    like this,

    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
    
    0 讨论(0)
  • 2021-02-06 23:20

    From the Docs on Popovers:

    Opt-in functionality:
    For performance reasons, the Tooltip and Popover data-apis are opt-in, meaning you must initialize them yourself.

    So you must call .popover() manually in JavaScript like this:

    $("[data-toggle=popover]").popover();
    

    Or you can use whatever selector you want

    Here's an example using StackSnippets.

    $("[data-toggle=popover]").popover();
    body {
      padding: 50px;
    }
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    
    
    <button type="button" class="btn btn-lg btn-danger" 
            data-toggle="popover" title="Popover title" 
            data-content="And here's some amazing content. It's very engaging. Right?">
      Click to toggle popover
    </button>

    Note: This is similar to the answer to Bootstrap Tooltip Not Showing Up

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