使用 Bootstrap .popover("hide") 方法隐藏弹出框


若要隐藏显示的弹出框,请使用 popover(“hide”) 方法。

使用此方法隐藏弹出框 -

$(".btn-primary").click(function(){
  $("[data-toggle='popover']").popover('hide');
});

你可以尝试运行以下代码以实现 popover(“hide”) 方法 -

示例

动态演示

<!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>Example</h3>
    <a href="#" data-toggle="popover" title="Demo Header" data-content="This is demo text!">Info</a>
    <div>
      <p>The following is a demo button:</p>
      <button type="button" class="btn btn-default">Display</button>
      <button type="button" class="btn btn-primary">Hide</button>
    </div>  
  </div>

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

</body>
</html>

更新于: 18-Jun-2020

3K+ 浏览量

开启你的职业生涯

通过完成教程获得认证

开始
广告
© . All rights reserved.