繁体   English   中英

Jquery Ui Datepicker 月/年下拉菜单在最新的 Firefox 中的弹出窗口中不起作用

[英]Jquery Ui Datepicker month/year dropdown is not working in popup in latest firefox

不知何故,我的 jQuery UI Datepicker Month/Year Dropdown 在最新的 firefox 的任何弹出窗口中都不起作用。

当我单击月份或年份下拉菜单时,不会出现选项列表。

这是我的弹出窗口和日期选择器代码:

$( "#dialog-form" ).dialog({
    modal: true
});

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

我也在 JSfiddle 上准备了一个演示:

http://jsfiddle.net/469zV/2/

这是因为模态强制将注意力集中在自身上。 这是这里提到的解决方案。 将以下脚本添加到您的 js 文件中。 就是这样。

jsfiddle: http : //jsfiddle.net/surjithctly/93eTU/16/

Ref: Twitter bootstrap 多模态错误

// Since confModal is essentially a nested modal it's enforceFocus method
// must be no-op'd or the following error results 
// "Uncaught RangeError: Maximum call stack size exceeded"
// But then when the nested modal is hidden we reset modal.enforceFocus
var enforceModalFocusFn = $.fn.modal.Constructor.prototype.enforceFocus;

$.fn.modal.Constructor.prototype.enforceFocus = function() {};

$confModal.on('hidden', function() {
    $.fn.modal.Constructor.prototype.enforceFocus = enforceModalFocusFn;
});

$confModal.modal({ backdrop : false });

对于 Bootstrap 4:

replace : $.fn.modal.Constructor.prototype.enforceFocus
By: $.fn.modal.Constructor.prototype._enforceFocus

我不得不使用

$.fn.modal.Constructor.prototype.enforceFocus = function () {
$(document)
  .off('focusin.bs.modal') // guard against infinite focus loop
  .on('focusin.bs.modal', $.proxy(function (e) {
    if (this.$element[0] !== e.target && !this.$element.has(e.target).length) {
      this.$element.focus()
    }
  }, this))
}

为了在我们使用 Tab 聚焦元素时限制模型内部的焦点(来自 GIT)。

试过这个>>

$("#dateOfBirth").datepicker({
    beforeShow: function(input, inst) {
        $(document).off('focusin.bs.modal');
    },
    onClose:function(){
        $(document).on('focusin.bs.modal');
    },
    changeYear: true,
    yearRange : '-150:+0'
});

现在我可以选择年份:)

理想的解决方案是在模态对话框中移动日期选择器弹出 div。

$("#dialog-form").dialog({
    modal: true,
    width: 500,
    height: 500
});

$("#datepicker").datepicker({
    changeMonth: true,
    changeYear: true,
    beforeShow: function(el, dp) {
          $(el).parent().append($('#ui-datepicker-div'));
          $('#ui-datepicker-div').hide();
        }    
    }
});

注意:将不得不稍微更新 css。 检查 jsfiddle 链接以获取实际演示。

JsFiddlehttp : //jsfiddle.net/469zV/414/

带有 jquery ui datepicker 的华丽弹出窗口(启用了 changemonth 和 changeyear)

试试这个代码

// Added to make calendar drop downs work properly
$.magnificPopup.instance._onFocusIn = function(e) {

    if( $(e.target).hasClass('ui-datepicker-month') ) {
        return true;
    }
    if( $(e.target).hasClass('ui-datepicker-year') ) {
        return true;
    }
    $.magnificPopup.proto._onFocusIn.call(this,e);
};

在现代——2018 年,使用 Bootstrap 4.1——我能够通过简单地将focus : false传递给模态构造函数来解决这个问题。

尝试这个:

beforeShow: function(el, dp) {
    uidp = $('#ui-datepicker-div').addClass('forced-display-none').detach();
    $(el).parent().append(uidp);
    setTimeout(function(){$(uidp).css({'position':'relative','left':'0px','top':'0px'}).removeClass('forced-display-none')},200);
}

将强制显示无定义为:

.forced-display-none {display: none !important;}

就我而言,我认为 datepicker 失败了,但真正发生的是以前引用的 datepicker (bootstrap-datepicker.js) 优先于 jquery-ui datepicker。

我为嵌套在引导模式中的 jquery daterangepicker 提供了一个解决方案(问题:选择器月\/年没有出现在 FF 浏览器上)。 解决方案是添加“parentEl”选项,指示要在其中初始化 daterangepicker 的模式:

 $('#example-date-input').daterangepicker({
            parentEl: $('.modal-where-daterangepicker-should-be-nested'),
            .....
 });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM