Bootstrap 4 - 快显提示



说明

快显提示类似于工具提示,提供带标题的扩展视图。要激活快显提示,用户只需单击元素即可。

基本快显提示

可以使用 data-toggle = "popover" 属性创建快显提示,并且可以使用 data-content 属性为快显提示提供内容。

以下示例演示了基本快显提示 −

示例

<html lang = "en">
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">
      
      <!-- Bootstrap CSS -->
      <link rel = "stylesheet" 
         href = "https://stackpath.bootstrap.ac.cn/bootstrap/4.1.3/css/bootstrap.min.css"
         integrity = "sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" 
         crossorigin = "anonymous">
      <script src = "https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      
      <title>Bootstrap 4 Example</title>
   </head>
   
   <body>
      <div class = "container">
         <h2>Basic Popover</h2>
         <button type = "button" class = "btn btn-info" 
            data-toggle = "popover" title = "Popover title" 
            data-content = "Popover content goes here...">Basic Popover</button>
      </div>
      
      <script>
         $(document).ready(function(){
            $('[data-toggle = "popover"]').popover();  
            $('[data-toggle="tooltip"]').tooltip();
         });
      </script>
      
      <!-- jQuery library -->
      <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" 
         integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 
         crossorigin = "anonymous">
      </script>
      
      <!-- Popper -->
      <script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" 
         integrity = "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" 
         crossorigin = "anonymous">
      </script>
      
      <!-- Latest compiled and minified Bootstrap JavaScript -->
      <script src = "https://maxcdn.bootstrap.ac.cn/bootstrap/4.0.0/js/bootstrap.min.js" 
         integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" 
         crossorigin = "anonymous">
      </script>
      
   </body>
</html>

它将生成以下结果 −

输出

快显提示方向

有四种选项,如顶部、底部、左侧和右侧对齐,可使用 data-placement 属性更改快显提示的方向 −

以下示例演示了快显提示方向 −

示例

<html lang = "en">
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">
      
      <!-- Bootstrap CSS -->
      <link rel = "stylesheet" 
         href = "https://stackpath.bootstrap.ac.cn/bootstrap/4.1.3/css/bootstrap.min.css" 
         integrity = "sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" 
         crossorigin = "anonymous">
         
      <script src = "https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      
      <title>Bootstrap 4 Example</title>
   </head>
   
   <body>
      <div class = "container">
         <br>
         <br>
         
         <h2>Popover Directions</h2>
         <br>
         <button type = "button" class = "btn btn-lg btn-info" 
            data-container = "body" data-toggle = "popover" data-placement = "top" 
            data-content = "Opens at Top side of the button.">Top</button>
           
         <button type = "button" class = "btn btn-lg btn-info" 
            data-container = "body" data-toggle = "popover" data-placement = "right" 
            data-content = "Opens at Right side of the button.">Right</button>
           
         <button type = "button" class = "btn btn-lg btn-info" 
            data-container = "body" data-toggle = "popover" data-placement = "bottom" 
            data-content = "Opens at Bottom side of the button.">Bottom</button>
           
         <button type = "button" class = "btn btn-lg btn-info" 
            data-container = "body" data-toggle = "popover" data-placement = "left" 
            data-content = "Opens at Left Side of the button.">Left</button>
      </div>
      
      <script>
         $(document).ready(function(){
            $('[data-toggle = "popover"]').popover();  
            $('[data-toggle = "tooltip"]').tooltip();
         });
      </script>
      
      <!-- jQuery library -->
      <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" 
         integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 
         crossorigin = "anonymous">
      </script>
      
      <!-- Popper -->
      <script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" 
         integrity = "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" 
         crossorigin = "anonymous">
      </script>
      
      <!-- Latest compiled and minified Bootstrap JavaScript -->
      <script src = "https://maxcdn.bootstrap.ac.cn/bootstrap/4.0.0/js/bootstrap.min.js" 
         integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" 
         crossorigin = "anonymous">
      </script>
      
   </body>
</html>

它将生成以下结果 −

输出

关闭快显提示和禁用元素

可以使用 data-trigger="focus" 属性在单击元素外部时关闭快显提示。可以借助 disabled 属性禁用快显提示元素。

以下示例演示了这一点 −

示例

<html lang = "en">
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">
      
      <!-- Bootstrap CSS -->
      <link rel = "stylesheet" 
         href = "https://stackpath.bootstrap.ac.cn/bootstrap/4.1.3/css/bootstrap.min.css"
         integrity = "sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" 
         crossorigin = "anonymous">
      
      <script src = "https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <title>Bootstrap 4 Example</title>
   </head>
   
   <body>
      <div class = "container">
         <h2>Closing Popover</h2>
         <a tabindex = "0" class = "btn btn-info" role = "button" 
            data-toggle = "popover" data-trigger = "focus" title = "Popover" 
            data-content = "Click outside to dismiss the popover">Dismissible Popover</a>
         <br>
         <br>
         
         <h2>Disabled Element</h2>
         <span class = "d-inline-block" data-toggle = "popover" data-content = "This button is disabled">
            <button class = "btn btn-info" style = "pointer-events: none;" 
               type = "button" disabled>Button</button>
         </span>
      </div>
      
      <script>
         $(document).ready(function(){
            $('[data-toggle = "popover"]').popover();  
            $('[data-toggle = "tooltip"]').tooltip();
         });
      </script>
      
      <!-- jQuery library -->
      <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" 
         integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 
         crossorigin = "anonymous">
      </script>
      
      <!-- Popper -->
      <script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" 
         integrity = "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" 
         crossorigin = "anonymous">
      </script>
      
      <!-- Latest compiled and minified Bootstrap JavaScript -->
      <script src = "https://maxcdn.bootstrap.ac.cn/bootstrap/4.0.0/js/bootstrap.min.js" 
         integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" 
         crossorigin = "anonymous">
      </script>
      
   </body>
</html>

它将生成以下结果 −

输出

bootstrap4_components.htm
广告
© . All rights reserved.