使用Bootstrap中的tooltip(“ show”)方法显示工具提示。如下所示,单击按钮即可看到工具提示:
$(document).ready(function(){ $(".btn-primary").click(function(){ $("[data-toggle='tooltip']").tooltip('show'); }); });
工具提示将在链接中可见,其中我已设置了data-toggle属性和链接文本,如以下代码段所示-
<a href="#" data-toggle="tooltip" title="工具提示可见!"> 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.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://cdn.staticfile.org/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>Demo</h3> <a href="#" data-toggle="tooltip" title="工具提示可见!">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>