Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 未使用Bootstrap.popover维护的类_Jquery_Class_Twitter Bootstrap_Popover - Fatal编程技术网

Jquery 未使用Bootstrap.popover维护的类

Jquery 未使用Bootstrap.popover维护的类,jquery,class,twitter-bootstrap,popover,Jquery,Class,Twitter Bootstrap,Popover,我正在使用Twitter引导弹出窗口添加标签 在popover中,我使用html选择器加载标签列表,当单击标签时,我添加一个类。问题是,当我关闭popover并想再次打开它时,设置的类将不再可见 这是我的JS: var isVisible = false; var clickedAway = false; $('.btn-label-popover').popover({ animation: true, placemen

我正在使用Twitter引导弹出窗口添加标签

在popover中,我使用html选择器加载标签列表,当单击标签时,我添加一个类。问题是,当我关闭popover并想再次打开它时,设置的类将不再可见

这是我的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?非常感谢

您丢失类的原因是,当popover被隐藏时,Twitter引导会将其从DOM中删除。您需要将每个更改的popover的id/类存储在一个数组中,并使用该id/类重新添加必要的类。例如:

var identifiers = [];

$('.btn-label-popover').popover({
        // your options
    }).click(function(e) {
        e.preventDefault();
        if(isVisible & clickedAway){
            $('.btn-label-popover').popover('hide');
            isVisible = clickedAway = false;
        } else {
            $(this).popover('show');

            // Loop through changed popovers
            for(i=0; i<identifiers.length, i++){
                $('.'+identifiers[i]+' span').toggleClass('label-inverse');
                $('.'+identifier[i]+' span').toggleClass('label-reminder');
            }
            clickedAway = false;
            isVisible = true;
        }
});

$('body').on('click', '.popover-content span', function(e){
    e.stopPropagation();
    var identifier = $(this).parent().attr('class');

    // Add to an array
    identifiers.push(identifier);

    $('.'+identifier+' span').toggleClass('label-inverse');
    $('.'+identifier+' span').toggleClass('label-reminder');
});
var标识符=[];
$('.btn标签popover').popover({
//你的选择
})。单击(功能(e){
e、 预防默认值();
如果(可见并单击路径){
$('.btn标签popover').popover('hide');
isVisible=ClickedWay=false;
}否则{
$(this.popover('show');
//循环浏览已更改的弹出窗口

for(i=0;我想知道你的答案,但事实并非如此。单击主体时不会删除类。只在单击标签本身时才切换,就像它应该做的那样。问题是,当我切换某些类时,然后关闭弹出窗口。之后,再次打开弹出窗口时,所有选定的标签(类)都不见了。啊,抱歉@ChrisKoster我对你在
上使用了一个选择器而感到意外。我会再看一看。我添加了一个修订的解决方案伙伴。非常感谢你的帮助Steve!现在开始工作。我还以为popover只是显示和隐藏了,因为我没有使用destroy。好吧,再次感谢你。