我正在使用 Twitter Bootstrap 弹出框添加标签。
在弹出窗口中,我使用 html 选择器加载标签列表,当单击标签时,我添加了一个类。问题是当我关闭弹出框并想要第二次打开它时,设置的类不再可见。
这是我的 JS:
var isVisible = false;
var clickedAway = false;
$('.btn-label-popover').popover({
animation: true,
placement: 'top',
title: 'Selecteer labels',
content: $('.controls .popover-content').html(),
trigger: 'manual'
}).click(function(e) {
e.preventDefault();
if(isVisible & clickedAway){
$('.btn-label-popover').popover('hide');
isVisible = clickedAway = false;
} else {
$(this).popover('show');
clickedAway = false;
isVisible = true;
}
});
$('body').on('click', '.popover-content span', function(e){
e.stopPropagation();
var identifier = $(this).parent().attr('class');
$('.'+identifier+' span').toggleClass('label-inverse');
$('.'+identifier+' span').toggleClass('label-reminder');
});
$(document).click(function(e) {
if(isVisible & clickedAway)
{
$('.btn-label-popover').popover('hide');
isVisible = clickedAway = false;
}
else
{
clickedAway = true;
}
});
$(document).keyup(function(e) {
if (e.keyCode == 27) {
if(isVisible & clickedAway)
{
$('.btn-label-popover').popover('hide');
isVisible = clickedAway = false;
} else {
clickedAway = true;
}
}
});
有没有办法通过添加的类来获取 HTML?非常感谢!