当前位置:   article > 正文

bootstrap4 提示框_bootstrap通知弹框

bootstrap通知弹框

提示框是一个小小的弹窗,在鼠标移动到元素上显示,鼠标移到元素外就消失。

如何创建提示框

通过向元素添加 data-toggle="tooltip" 来来创建提示框。

<a href="#" data-toggle="tooltip" title="提示内容">把鼠标移到到这里</a>

以下实例可以在文档的任何地方使用提示框:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Bootstrap 实例</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
  8. <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  9. <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
  10. <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
  11. </head>
  12. <body>
  13. <div class="container">
  14. <h3>提示框</h3><br>
  15. <a href="#" data-toggle="tooltip" title="提示内容">把鼠标移到到这里</a>
  16. </div>
  17. <script>
  18. $(document).ready(function(){
  19. $('[data-toggle="tooltip"]').tooltip();
  20. });
  21. </script>
  22. </body>
  23. </html>

运行效果

指定提示框的位置

默认情况下提示框显示在元素上方。

可以使用 data-placement 属性来设定提示框显示的方向: top, bottom, left 或 right:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Bootstrap 实例</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
  8. <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  9. <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
  10. <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
  11. </head>
  12. <body>
  13. <div class="container">
  14. <h3>提示框</h3><br>
  15. <a href="#" data-toggle="tooltip" data-placement="top" title="提示内容">鼠标移动到我这</a>
  16. <a href="#" data-toggle="tooltip" data-placement="bottom" title="提示内容">鼠标移动到我这</a>
  17. <a href="#" data-toggle="tooltip" data-placement="left" title="提示内容">鼠标移动到我这</a>
  18. <a href="#" data-toggle="tooltip" data-placement="right" title="提示内容">鼠标移动到我这</a>
  19. </div>
  20. <script>
  21. $(document).ready(function(){
  22. $('[data-toggle="tooltip"]').tooltip();
  23. });
  24. </script>
  25. </body>
  26. </html>

在按钮中使用:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Bootstrap 实例</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
  8. <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  9. <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
  10. <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
  11. </head>
  12. <body>
  13. <div class="container">
  14. <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="top" title="Tooltip on top">
  15. Tooltip on top
  16. </button>
  17. <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="right" title="Tooltip on right">
  18. Tooltip on right
  19. </button>
  20. <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom">
  21. Tooltip on bottom
  22. </button>
  23. <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="left" title="Tooltip on left">
  24. Tooltip on left
  25. </button>
  26. </div>
  27. <script>
  28. $(document).ready(function(){
  29. $('[data-toggle="tooltip"]').tooltip();
  30. });
  31. </script>
  32. </body>
  33. </html>

提示内容添加 HTML 标签,设置 data-html="true",内容放在 title 标签里头:

  1. <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-html="true" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
  2. Tooltip with HTML
  3. </button>
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Bootstrap 实例</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
  8. <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  9. <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
  10. <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
  11. </head>
  12. <body>
  13. <div class="container">
  14. <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-html="true" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
  15. Tooltip with HTML
  16. </button>
  17. </div>
  18. <script>
  19. $(document).ready(function(){
  20. $('[data-toggle="tooltip"]').tooltip();
  21. });
  22. </script>
  23. </body>
  24. </html>

禁用按钮:

  1. <span class="d-inline-block" tabindex="0" data-toggle="tooltip" title="Disabled tooltip">
  2. <button class="btn btn-primary" style="pointer-events: none;" type="button" disabled>Disabled button</button>
  3. </span>
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Bootstrap 实例</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
  8. <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  9. <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
  10. <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
  11. </head>
  12. <body>
  13. <div class="container">
  14. <span class="d-inline-block" tabindex="0" data-toggle="tooltip" title="Disabled tooltip">
  15. <button class="btn btn-primary" style="pointer-events: none;" type="button" disabled>Disabled button</button>
  16. </span>
  17. </div>
  18. <script>
  19. $(document).ready(function(){
  20. $('[data-toggle="tooltip"]').tooltip();
  21. });
  22. </script>
  23. </body>
  24. </html>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/80943
推荐阅读
相关标签
  

闽ICP备14008679号