我正在使用引导确认插件。如果在确认之外的任何地方发生点击,我将尝试关闭所有确认。不幸的是,每次点击它都会关闭。
$('html').on('mouseup', function(e) {
if ($(e.target).closest("[data-toggle='confirmation']").length === 0) {
$("[data-toggle='confirmation']").confirmation('hide');
}
这是 fiddle http://jsfiddle.net/zukdokpb/270/
最佳答案
您只需定位按钮而不是 html
:
$("#mybutton").on('click', function(e) {
if ($(e.target).closest("[data-toggle='confirmation']").length === 0) {
$("[data-toggle='confirmation']").confirmation('hide');
}
});
http://jsfiddle.net/zukdokpb/271/
如果您使用 data-popout
属性 ( new fiddle ),它应该会为您完成此操作
我看到您在第一个按钮上执行了此操作,但在第二个按钮上没有执行此操作。添加它应该可以修复默认功能。然后 $(e.target).closest("[data-toggle='confirmation']").length
返回 0
除非您实际单击原始按钮,所以它隐藏了所有其他点击的弹出窗口。
html:
<a href="#Delete" class="btn btn-primary btn-large" title="Deseja realmente excluir o projeto?" data-toggle="confirmation" data-singleton="true" data-placement="top" data-popout="true"><span title="Excluir o projeto">Excluir</span></a>
<button type="button" class="btn" ng-show="patient.Archived" data-toggle="confirmation" data-singleton="true" data-popout="true">
Archived
</button>
js:
$('[data-toggle="confirmation"]').confirmation({
btnOkLabel: " Sim",
btnCancelLabel: " Não"
});
关于javascript - 单击 Bootstrap 之外的任意位置时关闭 Bootstrap 确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47599784/