我正在尝试有按钮。当有人点击按钮时,会出现一个弹出窗口。在弹出窗口内,我有另一个按钮,当有人单击此按钮时,弹出窗口将隐藏。
效果很好,但是要再次打开弹出窗口,我必须单击按钮两次。
我的 HTML:
<button type="button" class="actif" data-container="body" data-toggle="popover" data-placement="right" data-content="<button type='button' class='annuler'>NOT</button>" data-html='true'>
ACTIVE
</button>
我的 jQuery:
$('[data-toggle="popover"]').popover();
$(document).on("click", ".annuler", function () {
$('[data-toggle="popover"]').popover('hide');
});
我做错了什么? 最好的问候
最佳答案
尝试不同的方式:
$(document).on("click", ".annuler", function (e) {
$('[data-toggle="popover"]').trigger('click');
});
$(function () {
$('[data-toggle="popover"]').popover();
});
<script src="//code.jquery.com/jquery-1.11.3.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<button type="button" class="actif" data-container="body" data-toggle="popover" data-placement="right"
data-content="<button type='button' class='annuler'>NOT</button>" data-html='true'>
ACTIVE
</button>
关于javascript - 如何使用弹出窗口内的按钮关闭弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34549994/