日期选择器在选择月份或年份时自动隐藏

Datepicker automatically hide on month or year select

本文关键字:隐藏 选择 日期 选择器      更新时间:2023-09-26

我可以在日期选择器中从日期返回到年份。但是当我尝试返回日期时,当我单击年份时,日期选择器会自动隐藏。

 var datePickerOptions = this.data || {}; 
    datePickerOptions.format = datePickerOptions.format || "mm-dd-yyyy";
    datePickerOptions.language = datePickerOptions.language || this.lang.code; 
    var $context = this;
    var dateContainer = this.container.find(".datepicker");
    dateContainer.datepicker(datePickerOptions).on('changeDate', function (ev) { 
    // here i'm getting the value 
    }); 
This because of bootstrap-datepicker.js .
on click event you can find like following.
case 'span':
                        if (!target.is('.disabled')) {
                            this.viewDate.setUTCDate(1);
                            if (target.is('.month')) {
                                var day = 1;
                                var month = target.parent().find('span').index(target);
                                var year = this.viewDate.getUTCFullYear();
                                this.viewDate.setUTCMonth(month);
                                this._trigger('changeMonth', this.viewDate);
                                if (this.o.minViewMode === 1) {
                                    this._setDate(UTCDate(year, month, day,0,0,0,0));
                                }
                            } else {
                                var year = parseInt(target.text(), 10)||0;
                                var day = 1;
                                var month = 0;
                                this.viewDate.setUTCFullYear(year);
                                this._trigger('changeYear', this.viewDate);
                                if (this.o.minViewMode === 2) {
                                    this._setDate(UTCDate(year, month, day,0,0,0,0));
                                }
                            }
                            this.showMode(-1);
                            this.fill();
                        }

而不是 this.fill() ,如果您像以下代码一样使用,这将按预期工作。

if (target.is('.month')) {

     if (!this._o.changeMonth) {
                                        this.fill();
                                    }
                                }
                                else {
                                    if (!this._o.changeYear) {
                                        this.fill();
                                    }
                                }

我希望,这会对你有所帮助。