使用Bootstrap 3.x Popovers时,我可以通过更改选项并重新显示Popover来更改Popover标题和内容(可见时),如下所示:
var popover = $('#myid').data('bs.popover');
popover.options.title = "My Title";
popover.options.content = "My content";
$("#myid").popover('show');
在Bootstrap 4.x中这不再起作用。
在4.x中有类似的方法吗?
答案 0 :(得分:2)
答案在这里:bootstrap popover change content dynamically
$('[data-toggle="popover"]').popover()
$('#myid').attr('data-original-title', 'New title');
$('#myid').attr('data-content', 'New content');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<button id="myid" type="button" class="btn btn-lg btn-danger" data-toggle="popover" title="Popover title" data-content="And here's some amazing content. It's very engaging. Right?">Click to toggle popover</button>