javascript
  • jquery
  • html
  • twitter-bootstrap
  • 2016-11-17 76 views 0 likes 
    0

    我已经用一些自定义jquery的引导popover。 Popover功能工作正常,但如果我添加一个外部链接按钮,它不工作。请参阅代码:有两个用于弹出对话框的按钮“Button1”&“Button2”用于外部链接。Bootstrap:popover按钮链接不工作

    $(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>

    +0

    你想酥料饼的出现,当你的用户去在它与自己的鼠标或链接后点击?因为我有最后的选择。 –

    +0

    它按预期工作正常。我检查了我的本地。 – Samir

    +0

    你需要在第二个按钮点击另一个URL?或者你想通过第二个按钮打开相同的弹出窗口?像第一个按钮? – Samir

    回答

    1

    你错过了一些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> 
    
    +0

    很好,但它不能在iphone浏览器中工作 – Vishnu

    +0

    更改类为'class =“btn”' –

    +0

    哪个按钮? – Vishnu

    1

    堆栈溢出脚本阻止您的链接打开新页面/重定向。试试这个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'); 
        } 
        }); 
    }); 
    
    +0

    有一个问题...它不工作在iPhone浏览器.. – Vishnu

    +0

    工具提示或简单的链接? –

    +0

    工具提示。它不“解雇”当我们点击身体上的任何地方(只在iphone浏览器中) – Vishnu

    相关问题