【问题标题】:How to add a class to a popover title如何将类添加到弹出框标题
【发布时间】:2016-02-11 03:40:06
【问题描述】:

我正在使用弹出框的引导元素,但我不知道如何将其归为一个类。我想为每个不同的班级创建一个自定义的背景颜色。 这是我的弹出窗口构建(在 javascript 中)

$(element).popover({
                    'placement': 'top',
                    'animation': true,
                    'html': true,
                    'title' : variable,
                    'content': html
                });

                $(element).popover('show');

如果我这样做:

$(element).popover({
                    'placement': function(context, src) {
                        $(context).addClass($(src).data('customClassName'));
                        return 'top';},
                    'animation': true,
                    'html': true,
                    'title' :feature.get('features')[0].get('name') + ' (' +  feature.get('features')[0].get('type') + ')',
                    'content': html
                });
                $(element).popover().addClass('TESTCLASS');
                $(element).popover('show');

给出的结果将是

如您所见,该类与 popover-title 不在同一个 div 中

【问题讨论】:

  • $(element).popover().addClass('yourclass')
  • @Raviteja 生成的类在兄弟姐妹上,我必须先到达兄弟姐妹,然后是孩子才能获得 popover-title 类,我的问题首先是我是否可以将类添加到 popover-直接标题
  • @HemrajJain 已给出答案,但谢谢

标签: javascript jquery twitter-bootstrap


【解决方案1】:

您可以使用template 属性定义您的自定义模板:

function getPopoverCustomTemplate(className) {
    return '<div class="popover ' + className + '" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>';
}

$(element).popover({
    'placement': 'top',
    'animation': true,
    'html': true,
    'title' : variable,
    'content': html,
    'template': getPopoverCustomTemplate('myCustomClass')
});

【讨论】:

  • 这正是我想要的,我把类名放在popover-title类上,谢谢!
猜你喜欢
  • 1970-01-01
  • 2023-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-12
  • 2020-01-19
  • 2022-01-18
相关资源
最近更新 更多