【问题标题】:Make Twitter's Bootstrap 2.x Popover use the default Popover title instead of that in the html title attribute?让 Twitter 的 Bootstrap 2.x 弹出框使用默认弹出框标题而不是 html 标题属性中的标题?
【发布时间】:2013-07-04 17:10:30
【问题描述】:

我有以下锚元素,单击该元素时应显示 Twitter Bootstrap 弹出框:

<a href="javascript:void(0)" class="popover_toggle" title="View Image">View Image</a>

我还有以下 javascript 来附加弹出框并为其设置默认标题:

$('.popover_toggle').popover({
    title: 'Login Required!'
});

我希望 Popover 具有在 javascript“需要登录!”中定义的默认标题,而不是在锚元素“查看图像”中定义的标题。我怎样才能做到这一点?

【问题讨论】:

    标签: twitter-bootstrap


    【解决方案1】:

    正如http://twitter.github.io/bootstrap/javascript.html#popovers(如果title 属性不存在,则默认标题值)告诉您:只有当您的元素具有空标题属性或没有标题属性时,您才能设置标题。

    当标题选项设置为字符串时,它会在文档就绪时进行评估。在此处使用函数(触发时求值)仍然不起作用。

    Popovers 是工具提示类的扩展。它的构造函数调用 fixTitle()。 fixTitle() 将内容从 title-attribute 移动到 data-orginal-title 属性。因为这是在调用 setTitle() 之前完成的,所以不能使用 title 函数。

    为了解决您的问题,否决 popover 类的 fixTitle():

    $.fn.popover.Constructor.prototype.fixTitle = function () { return; }
    

    现在 popover 将忽略(您的 title 属性)并使用您在 popover 调用中设置的标题:

    html

       <a href="javascript:void(0);" class="popover_toggle" title="View Image">View Image</a>
    

    javascript

    $.fn.popover.Constructor.prototype.fixTitle = function () {return;}
    $('.popover_toggle').popover({
        title: 'Login Required!',
    });
    

    另见:http://bootply.com/66591

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-28
      相关资源
      最近更新 更多