-1
我正在使用Krajee Bootstrap Popover X。它的效果很好,除了當我在彈出窗口外單擊時它不會關閉。只有當我點擊觸發彈出窗口或其他popover按鈕的按鈕時,它纔會關閉。我試着從這裏的例子How to dismiss a Twitter Bootstrap popover by clicking outside?,但它沒有工作jQuery:如何在外部點擊時關閉彈出窗口?
我正在使用Krajee Bootstrap Popover X。它的效果很好,除了當我在彈出窗口外單擊時它不會關閉。只有當我點擊觸發彈出窗口或其他popover按鈕的按鈕時,它纔會關閉。我試着從這裏的例子How to dismiss a Twitter Bootstrap popover by clicking outside?,但它沒有工作jQuery:如何在外部點擊時關閉彈出窗口?
這是我自己的問題的解決方案。
var idpop = []; //Creating an array to store the id
//Since that when you create a popover using Krajee Popoover X plugin,
//you always add id's to it.
//By default, only one popover will displayed at a time.
$('.popover').on('shown.bs.modal', function() {
//Get the id of the popover that is currently displayed
idpop.push($(this).attr('id')); //Add the id to the Array
});
$('.popover').on('hidden.bs.modal', function() {
//Empty the array when the popover is dismissed
idpop = [];
});
$('html').on('click', function(e) {
//when click outside the popover then dismiss the popover
if ($(e.target).closest('.popover').length == 0) {
$('#' + idpop[0]).popoverX('hide');
}
});
你能提供樣品的jsfiddle你有什麼,你什麼嘗試? – Grundy