简体   繁体   English

引导程序:弹出按钮单击

[英]Bootstrap: popover button click

I have used bootstrap popover function, its working now.. but i need to "dismiss" popover box if i click anywhere in the page. 我已经使用了bootstrap popover功能,它现在可以正常工作。.但是,如果我单击页面中的任意位置,则需要“关闭” popover框。 please check the code that i have used. 请检查我使用的代码。

First click on the button then i need to "dismiss" popover box on clicking the black space (now its dismiss only when we clicked on the same button). 首先单击按钮,然后在单击黑色空间时“关闭”弹出框(现在只有在单击同一按钮时才关闭它)。

 $(document).ready(function() { $('[data-toggle="popover"]').popover(); }); 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> <div class="container" style="width:400px; height:400px; background:#000;padding-top:50px;"> <a href="#" title="Header" data-toggle="popover" data-content="Some content" class="btn btn-danger">Click here</a> <br> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 

Just use data-trigger="focus" in a tag 只需使用data-trigger="focus"a标签

For more info check Dismissible popover 有关更多信息,请检查“可允许的弹出窗口”

 $(document).ready(function() { $('[data-toggle="popover"]').popover(); }); 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> <div class="container" style="width:400px; height:400px; background:#000;padding-top:50px;"> <a href="#" title="Header" data-toggle="popover" data-content="Some content" class="btn btn-danger" data-trigger="focus">Click here</a> <br> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 

This will work 这会起作用

Use below javascript for dismiss popover when outside click 在外部点击时,使用下面的JavaScript消除弹出窗口

$('body').on('click', function (e) {
    $('[data-toggle="popover"]').each(function () {
        //the 'is' for buttons that trigger popups
        //the 'has' for icons within a button that triggers a popup
        if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
            $(this).popover('hide');
        }
    });
});

Try this 尝试这个

$(document).ready(function(){
 $('[data-toggle="popover"]').popover({trigger:'focus'});
});

 $(document).ready(function(){ $('[data-toggle="popover"]').popover({trigger:'focus'}); }); 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="container" style="width:400px; height:400px; background:#000;padding-top:50px;"> <a href="#" title="Header" data-toggle="popover" data-content="Some content" class="btn btn-danger">Click here</a><br> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM