如何从bootstrap中的popover获取popover

时间:2016-08-27 15:06:03

标签: bootstrap-popover

我尝试下面的代码,我没有得到第二个弹出窗口,我的方法似乎有一些问题,我不想得到第二个弹出窗口...



$(function() {
    $(".pendingList, .pendings").popover();
 });

.icon3{
	background: url('http://blog.flattr.net/wp-content/uploads/2011/09/stackoverflow.png') 1px 1px no-repeat;
	background-position: center;
	height:100px;
}

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

<div class="icon3 pendingList" data-toggle="popover" data-trigger="click" data-html="true" data-placement="bottom" 
													data-content="<a href='#' class='pendings' data-toggle='popover' data-trigger='click' data-html='true' data-placement='bottom' 
												data-content='test' >Pending(5)</a>"></div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

您的代码不起作用,因为执行popover方法时元素不存在。试试下面的代码,它运行正常!

$(function() {
    $(".pendingList").popover();
    $('.pendingList').on('inserted.bs.popover', function () {
      $(".pendings").popover();
    });
 });
.icon3{
	background: url('http://blog.flattr.net/wp-content/uploads/2011/09/stackoverflow.png') 1px 1px no-repeat;
	background-position: center;
	height:100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div class="icon3 pendingList" data-toggle="popover" data-trigger="click" data-html="true" data-placement="bottom" data-content="<a href='#' class='pendings' data-toggle='popover' data-trigger='click' data-html='true' data-placement='bottom' data-content='test' >Pending(5)</a>"></div>