要在单击按钮时切换弹出窗口,请使用popver(“ toggle”)方法。
设置弹出开关为-
$(document).ready(function(){ $(".btn-default").click(function(){ $("[data-toggle='popover']").popover('toggle'); }); });
单击按钮时,弹出窗口将生成-
<button type="button" class="btn btn-default"> (Course) Toggle Popover </button>
单击按钮后,弹出程序会在链接上生成弹出框-
<a href="#" data-toggle="popover" title="Languages" data-content="C, C++, Java"> Learn </a>
以下是说明popver(“ toggle”)方法用法的示例-
<!DOCTYPE html> <html> <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"> <a href="#" data-toggle="popover" title="Languages" data-content="C, C++, Java">Learn</a> <div> <p>The following is the button:</p> <button type="button" class="btn btn-default">(Course) Toggle Popover</button> </div> </div> <script> $(document).ready(function(){ $(".btn-default").click(function(){ $("[data-toggle='popover']").popover('toggle'); }); }); </script> </body> </html>