【发布时间】:2015-01-29 13:59:03
【问题描述】:
我有一组动态的 contenteditable div。具有类“.showPopover”的 div 将有一个弹出窗口。弹出框触发器设置为手动,因为我希望它们显示在焦点上,但并不总是隐藏在模糊中。
我在这里找到[问题]:Bootstrap Tooltip with manual trigger and selector option 我不能将“选择器方法”与手动触发器一起使用,所以我遵循了那里的答案之一,但是对于动态添加的 div,仍然没有出现弹出框。
问题是,我只想为具有特定类的 div 显示弹出框,而不是与 div 一起添加。
弹出框的 div 类的更改通过启用按钮进行了一些简化。
jQuery(document).ready(function($) {
$('a.add').on('click', function(event) {
event.preventDefault();
$('.container').append('<p class="input" contenteditable="true"></p>');
});
$('a.enable').on('click', function(event) {
event.preventDefault();
$('.input').not('.showPopover').addClass('showPopover');
});
$('.container').on('focus', '.input.showPopover', function(event) {
if (!$(this).data("bs.popover")) {
$(this).popover({
placement:'right',
trigger:'manual',
html:true,
content:'<a href="#" class="btn btn-danger">Remove</a>'
});
}
$(this).popover('show');
});
var mousedownHappened = false;
$('.container').on('blur', '.input', function(event) {
if(mousedownHappened) {
mousedownHappened = false;
} else {
$(this).popover('hide');
}
});
$('.container').on('mousedown', '.popover .btn', function(event) {
mousedownHappened = true;
});
});
Jsfiddle:http://jsfiddle.net/Lh2rpj0f/2/
jQuery 1.11.1,引导 3.3.2
感谢 Yenne Info,我找到了一个可行的解决方案: http://jsfiddle.net/Lh2rpj0f/4/
这可能不是最好的解决方案,但它完全符合我的要求。 (当我单击弹出框内的按钮时,单击启用按钮时不会破坏此弹出框。)
至于现在,我的最终解决方案:Bootstrap popover with manual trigger attached on dynamic content
【问题讨论】:
标签: javascript jquery twitter-bootstrap bootstrap-popover