How to insert close button in popover for bootstrap

前端 未结 25 2964
忘了有多久
忘了有多久 2020-11-29 20:53

JS:

$(function(){
  $(\"#example\").popover({
    placement: \'bottom\',
    html: \'true\',
    title : \'         


        
25条回答
  •  日久生厌
    2020-11-29 21:27

    I have struggle with this one and this is the simplest way to do it, 3 lines of js:

    1. Add a cross in the title of the popover
    2. use the js snippet to show the popover and to close by clicking the header
    3. Use a bit of css to make it nice

    $(document).ready(function() {
      // This is to overwrite the boostrap default and show it allways
      $('#myPopUp').popover('show');
      // This is to destroy the popover when you click the title
      $('.popover-title').click(function(){
        $('#myPopUp').popover('destroy');
      });
    });
    @import "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css";
    
    /* Just to align my example */
    .btn {
      margin: 90px auto;
      margin-left: 90px;
    }
    
    /* Styles for header */
    .popover-title {
      border: 0;
      background: transparent;
      cursor: pointer;
      display: inline-block;
      float: right;
      text-align: right; 
    }
    
    
        
      
     

提交回复
热议问题