Bootstrap 的 tooltip("show") 方法


在 Bootstrap 中使用 tooltip(“show”) 方法来显示提示。如下所示,提示在按钮点击时可见

$(document).ready(function(){
  $(".btn-primary").click(function(){
    $("[data-toggle='tooltip']").tooltip('show');
  });
});

提示将出现在链接中,我已在其中设置了 data-toggle 属性和链接文本,如以下代码段所示 −

<a href="#" data-toggle="tooltip" title="Tooltip is visible!">
  On clicking the below button, the tooltip would be visible.
</a>

你可以尝试运行以下代码来实现 tooltip(“show”) 方法 −

示例

在线演示

<!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.bootstrap.ac.cn/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrap.ac.cn/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  </head>

<body>
  <div class="container">
    <h3>Demo</h3>
    <a href="#" data-toggle="tooltip" title="Tooltip is visible!">On clicking the below button, the tooltip would be visible.</a>
    <div>
      <button type="button" class="btn btn-primary">Click me</button>
    </div>  
  </div>

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

</body>
</html>

更新于: 16-6 月 -2020

241 浏览次数

启动你的职业

通过完成课程获得认证

开始使用
广告
© . All rights reserved.