我想在右上角的bootstrap popover插件中插入一个关闭按钮,如图所示,我尝试了很多方式,其他人在互联网上提出但是它不起作用,也许我做错了方法..
Something like the red close button on the top right corner
<nav class="navbar">
<div class="container navbar-cart">
<ul class="navbar-nav ml-auto">
<li>
<a id="cart-popover" class="btn" data-placement="left" title="Shopping Cart">
<i class="fa fa-shopping-cart"></i>
<span class="badge"></span>
<span class="total_price">RM 0.00</span>
</a>
</li>
</ul>
</div>
</nav>
<div id="popover_content_wrapper" style="display: none">
<button type="button" class="close">×</button>
<span id="cart_details"></span>
<div align="right">
<a href="#" class="btn btn-primary" id="check_out_cart">
<i class="fa fa-shopping-cart"></i> Check Out
</a>
<a href="#" class="btn btn-danger" id="clear_cart">
<i class="fa fa-trash"></i> Clear
</a>
</div>
</div>
//show cart
$('#cart-popover').popover({
html : true,
content:function(){
return $('#popover_content_wrapper').html();
}
});
$('.close').on('click', function (event) {
$('#popover_content_wrapper').hide();
});
答案 0 :(得分:1)
这是您的预期输出:
在此处阅读更多内容:http://getbootstrap.com/docs/4.1/components/popovers/#options
$(document).ready(function(){
$('#cart-popover').popover({
html : true,
title:function(){
return $('.popover_title').html();
},
content:function(){
return $('#popover_content_wrapper').html();
}
});
});
$(document).on('click','.close-popover',function(){
$('#cart-popover').popover('hide');
});
&#13;
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<nav class="navbar">
<div class="container navbar-cart">
<ul class="navbar-nav ml-auto">
<li>
<a id="cart-popover" class="btn" data-placement="left">
<i class="fa fa-shopping-cart"></i>
<span class="badge"></span>
<span class="total_price">RM 0.00</span>
</a>
</li>
</ul>
</div>
</nav>
<div class="popover_title" style="display: none">
<h6>Shopping Cart<span class="close-popover float-right text-danger "><i class="fas fa-times"></i></span></h6>
</div>
<div id="popover_content_wrapper" style="display: none">
<span id="cart_details"></span>
<div align="right">
<a href="#" class="btn btn-primary" id="check_out_cart">
<i class="fa fa-shopping-cart"></i> Check Out
</a>
<a href="#" class="btn btn-danger" id="clear_cart">
<i class="fa fa-trash"></i> Clear
</a>
</div>
</div>
&#13;