在bootstrap-modal中的datepicker中的月份选择在Firefox中不起作用

des*_*ien 4 jquery-ui-datepicker twitter-bootstrap bootstrap-modal

如果日期选择器中的月份选择在引导模式中,则它在FireFox中不起作用.

<button class="btn" id="btn">Click Me</button>

<div class="modal hide" id="modal" tabindex="-1">
    <div class="modal-body">
        <input type="text" id="datepicker" />        
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

JavaScript的:

$("#datepicker").datepicker({"changeMonth": true});

$('#btn').click(function() {
    $("#modal").modal('show');
});
Run Code Online (Sandbox Code Playgroud)

这是一个缩小的例子:http://jsfiddle.net/nKXF2/

我找到了一个类似的twitter-bootstrap github问题:https://github.com/twbs/bootstrap/issues/5979

des*_*ien 20

我发现了这个bug的两个修复:

修复1:如果你删除div.modal中的tabindex attr,月份选择工作正常. 我对此解决方案唯一的问题是,在IE(任何版本)上,您仍然需要双击月份下拉菜单才能打开它.

修复2:您可以在以下网址找到第二个解决方案:http://jsfiddle.net/nKXF2/1/通过覆盖此问题中提出的enforceFocus函数,您可以再次使用月份下拉列表.

$('#modal').on('show', function () {
    $.fn.modal.Constructor.prototype.enforceFocus = function () { };
});
Run Code Online (Sandbox Code Playgroud)

我认为第二个是最好的.

  • 第二次修复对我来说.事件可能在最近的Bootstrap版本中发生了变化,因为我不得不使用它:`$('#modal').on('show.bs.modal'...` (3认同)