如何将引导徽章放置在引导工具提示上?

时间:2019-01-10 04:54:25

标签: css datatable bootstrap-4 badge

我尝试

<td>
    <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top"  data-placement="top"  title="<span class="badge badge-pill badge-primary">15</span>">
           <i class="fas fa-list-alt"></i>
    </button>
</td>

但是我只得到'<span class="badge badge-pill badge-primary">15</span>'而不是html徽章吗? 如何将html放在工具提示标题中?

我尝试使用data-html =“ ture”,但仍然失败! 我要的最终目的是

<td>
    <button type="button" class="btn btn-default" data-toggle="tooltip"  data-html="ture" data-placement="top"  data-placement="top"  title="<span class="badge badge-pill badge-primary">15</span><span class="badge badge-pill badge-secondary">16</span><span class="badge badge-pill badge-warning">17</span>">
           <i class="fas fa-list-alt"></i>
    </button>
</td>

我刚得到一个徽章的提示

https://jsfiddle.net/housekeepings/rm0uade9/32/

<html>
<body>
<table id="table_id" class="display">
<thead>
  <tr>
    <th>
      head1
    </th>
    <th>
      head2
    </th>
    <th>
      head3
    </th>
  </tr>
</thead>
<tbody>
  <tr>
  <td>
   see1 
  </td>
    <td>
       <div class="btn-group">
          <button type="button" class="btn btn-default" data-toggle="tooltip"  data-html="true"  data-placement="top"  title="<span class="badge badge-pill badge-primary">10</span>"
> 
             <i class="fas fa-list-alt"></i>
          </button>
        </div>
    </td>
    <td>
       <div class="btn-group">
          <button type="button" class="btn btn-default" data-toggle="tooltip"  data-html="true"  data-placement="top"  title="<em>Tooltip</em> <u>with</u> <b>HTML</b>"> 
             <i class="fas fa-list-alt"></i>
          </button>
        </div>
     </td>
    <td>
     <div class="btn-group">
          <button type="button" class="btn btn-default" data-toggle="tooltip"  data-html="true"  data-placement="top"  title="Something with badge <span class='badge badge-primary'>12</span>"> 
             <i class="fas fa-list-alt"></i>
          </button>
        </div>  
    </td>
   </tr>
</tbody>
</table>
</body>
</html>

3 个答案:

答案 0 :(得分:1)

您必须添加

data-html="true" 

在标题中添加html时。

<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-html="true" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
  Tooltip with HTML
</button>

检出this

$(function () {
  $('[data-toggle="tooltip"]').tooltip()
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-html="true" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
  Tooltip with HTML
</button>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

编辑:

您的数据表js损坏,导致工具提示无法初始化 如果我把它放在数据表之前检查一下 https://jsfiddle.net/rm0uade9/34/,您需要先解决数据表错误。

答案 1 :(得分:1)

尝试此解决方案

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

   
<br> <br> <br>

<table>
  <tr>
    <td>
      <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top"  data-placement="top" class="badge badge-pill badge-primary" title="15">
      <span >button</span>
             <i class="fas fa-list-alt"></i>
      </button>
    </td>
  </tr>
</table>

<script>
$(document).ready(function(){
  $('[data-toggle="tooltip"]').tooltip();   
});
</script>

   

</body>
</html>

答案 2 :(得分:1)

您可以在工具提示上放置徽章或多个徽章 示例
引导程序3

$(document).ready(function(){
          $('[data-toggle="tooltip"]').tooltip();   
        });
    <!DOCTYPE html>
        <html lang="en">
        <head>
          <title>Bootstrap Example</title>
          <meta charset="utf-8">
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        </head>
        <body>
        
        
        <div class="container">
          <h3>Tooltip Example</h3>
          
          <a href="#" data-toggle="tooltip" data-html="true"
          title="Badge <span class='badge badge-primary'>12</span> <span class='badge badge-primary'>12</span>">
          
          Hover over me
          </a>
          
        </div>
       
        
        </body>
        </html>

引导程序4

 $(document).ready(function(){
      $('[data-toggle="tooltip"]').tooltip();   
    });
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  <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.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</head>
<body>
 <div class="container">
      <h3>Tooltip Example</h3>

      <a href="#" data-toggle="tooltip" data-html="true"
      title="Badge <span class='badge badge-primary'>12</span><span class='badge badge-primary'>12</span> <span class='badge badge-primary'>12</span>">

      Hover over me
      </a>

    </div>

    </body>
</body>
</html>

两者都能正常工作。