簡體   English   中英

引導程序:彈出按鈕鏈接不起作用

[英]Bootstrap: popover button link not working

我已將Bootstrap Popover與一些自定義的jquery一起使用。 彈出功能正常運行,但是如果我添加了帶有外部鏈接的按鈕,則無法正常工作。 參見代碼: 有兩個按鈕“ Button1”用於彈出按鈕,“ Button2”用於外部鏈接。

 $(document).ready(function () { $("body").tooltip({ selector: "[data-toggle='tooltip']", container: "body" }) .popover({ selector: "[data-toggle='popover']", container: "body", html: true }); }); $('body').on('click', function (e) { $('[data-toggle="popover"]').each(function () { if(!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) { $(this).popover('hide'); } }); }); 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="container" style="width:400px; height:400px; background:#000;padding-top:50px;"> <a data-placement="top" role="button" class="btn btn-danger" data-toggle="popover" data-content="Popover" data-original-title="" title=""> Button1 </a> <a class="btn btn-danger" href="http://facebook.com" target="_blank">Button2</a> </div> 

第二個按鈕中缺少一些data-toggledata-placement語法! 添加這些將使第二個按鈕具有與第一個按鈕相同的功能。 我已將此添加到您的代碼中:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript"> $(document).ready(function () {
        $("body").tooltip({
            selector: "[data-toggle='tooltip']",
            container: "body"
        })
                .popover({
                    selector: "[data-toggle='popover']",
                    container: "body",
                    html: true
                });
    });

    $('body').on('click', function (e) {
        $('[data-toggle="popover"]').each(function () {
            if(!$(this).is(e.target) &&
                    $(this).has(e.target).length === 0 &&
                    $('.popover').has(e.target).length === 0) {
                $(this).popover('hide');
            }
        });
    });</script>

<div class="container" style="width:400px; height:400px; background:#000;padding-top:50px;">
    <a data-placement="top" role="button" class="btn btn-danger" data-toggle="popover" data-content="Popover" data-original-title="" title="">
        Button1
    </a>

    <a class="btn btn-danger" href="http://facebook.com" data-placement="top" data-toggle="popover" data-content="Popover" data-original-title="" title="" target="_blank">Button2</a>
</div>

堆棧溢出腳本阻止您的鏈接打開新頁面/重定向。 使用您的代碼嘗試此Codepen: http ://codepen.io/TunderScripts/pen/oYYbgW

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div class="container" style="width:400px; height:400px; background:#000;padding-top:50px;">
  <a data-placement="top" role="button" class="btn btn-danger" data-toggle="popover" data-content="Popover" data-original-title="" title="">
    Button1
  </a>

  <a class="btn btn-danger" href="http://facebook.com" target="_blank">Button2</a>
</div>


$(document).ready(function () {
  $("body").tooltip({   
    selector: "[data-toggle='tooltip']",
    container: "body"
  })
  .popover({
    selector: "[data-toggle='popover']",
    container: "body",
    html: true
  });
});

$('body').on('click', function (e) {
  $('[data-toggle="popover"]').each(function () {
    if(!$(this).is(e.target) &&
       $(this).has(e.target).length === 0 &&
       $('.popover').has(e.target).length === 0) {
      $(this).popover('hide');
    }
  });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM