datepicker onselect未触发来自gridmvc.js插件

时间:2013-10-31 10:33:40

标签: javascript jquery

dateContainer.datepicker({
    defaultDate: this.filterValue,
    changeMonth: true,
    changeYear: true,
    dateFormat: 'MM-dd-yyyy',
    onSelect: function (dateText, t) {
        var type = $context.container.find(".grid-filter-type").val();
        $context.cb(type, dateText);
    }
});

我正在使用gridmvc.js和bootstrap-datepicker.js插件。 无论如何,OnSelect事件不会发射。我不知道是什么原因?

1 个答案:

答案 0 :(得分:0)

我不知道因为什么,问题就发生了。但我找到了临时解决方案。对于解决方案,您需要在bootstrap-datepicker.js中更改一行代码。 (在更改和使用插件之前检查许可证)

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()被调用,因此出现了问题。

如果你在插件中评论这一行,则datepicker将不会在月份和年份的变化中隐藏任何方式。或者您可以通过以下方式进行更改,

if (target.is('.month')) {
                                if (!this._o.changeMonth) {
                                    this.fill();
                                }
                            }
                            else {
                                if (!this._o.changeYear) {
                                    this.fill();
                                }
                            }

然后根据您在创建datepicker时给出的参数,这将有效。