【问题标题】:Datepicker in Popover Won't display弹出窗口中的日期选择器不会显示
【发布时间】:2013-03-22 18:28:52
【问题描述】:

使用Twitter BootstrapBootstrap-datepicker 扩展。我无法在 popover 中显示日期选择器。

<a href="#" id="add-event-button" class="btn btn-small">Add an Event</a>

$(document).ready(function () {

    $("#add-event-button").popover({
        title: "Add an Event",
        placement: 'bottom',
        content: '<input class="datepicker" type="text" />',
        html: true
    }).click(function (e) {
        e.preventDefault();
    });
});

弹出框显示得很好,弹出框上下文之外的&lt;input class="datepicker" type="text" /&gt; 可以很好地显示日期选择器。有什么想法吗?

【问题讨论】:

    标签: jquery twitter-bootstrap datepicker


    【解决方案1】:

    尝试使用回调扩展弹出功能,因为日期选择器无法在加载时添加到不存在的元素,试试这个:

    var tmp = $.fn.popover.Constructor.prototype.show;
    $.fn.popover.Constructor.prototype.show = function () {
      tmp.call(this);
      if (this.options.callback) {
        this.options.callback();
      }
    }
    
    $("#add-event-button").popover({ 
      title: "Add an Event",
      placement: 'bottom',
      content: '<input class="datepicker" type="text" />',
      html: true, 
      callback: function() { 
        $('.datepicker').datepicker(); 
      }
    }).click(function (e) {
      e.preventDefault();
    });
    

    编辑:来自这里的回调扩展解决方案:Callback function after tooltip / popover is created with twitter bootstrap?

    【讨论】:

    • 感谢@naturalethic,我还发现使用“inserted.bs.popover”事件效果更好,因为它与弹出框的定位配合得很好。将弹出框模板添加到 dom 后立即调用它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-06
    • 2021-11-17
    • 2021-12-22
    • 1970-01-01
    相关资源
    最近更新 更多