onSelect不绑定第一次加载

时间:2013-10-14 13:16:51

标签: jquery

下面提到的方法的onSelect操作无法首次加载。但是当我按F5时它正在工作。可以说为什么?

            var multiDatesPickerBinding = function () {
                $('.button-set').buttonset();

                $(".datePicker").each(function () {
                    var target = $(this);
                    target.datepicker({ showAnim: '', changeMonth: true, minDate: target.data('min'), changeYear: true, dateFormat: 'm/d/yy', yearRange: 'c-20:c+10' });
                });
                $('.enumeration').buttonset();

                $.datepicker._getDate = function (inst) {
                    var startDate = (!inst.currentYear || (inst.input && inst.input.value == '') ? null :
                        this._daylightSavingAdjust(new Date(
                            inst.currentYear, inst.currentMonth, inst.currentDay)));
                    return startDate;
                };

                $.datepicker._defaults.dateFormat = 'yy-mm-dd';
                $.valHooks['multiDatesPicker'] = { get: function (elem) { return $(elem).multiDatesPicker('getDates'); } }; //, set: function (elem, v) { $(elem).multiDatesPicker('addDates', v); } };
                $.valHooks['datepicker'] = { get: function (elem) { return $(elem).datepicker('getDate'); } }; //, set: function (elem, v) { $(elem).datepicker('setDate', v); } };

                window.checkForCalendars = function () {
                    $('.inline-calendar,.inline-multi-calendar').each(function () {
                        var self = $(this);
                        var type = 'datepicker';
                        var format = 'yy-mm-dd';
                        var target = self.data('target');
                        var value = self.data('value');
                        var args = {
                            dateFormat: format,
                            onSelect: function () { alert('sam'); }
                        };
                        args['numberOfMonths'] = self.data('months') || 1;
                        args['minDate'] = self.data('min');
                        args['maxDate'] = self.data('max');

                        if (self.data('multi')) {
                            type = 'multiDatesPicker';
                            value = value ? value.split(',') : null;
                        }
                        if (target) {
                            var rawValue = $('#' + target).val();
                            if (rawValue)
                                value = $.datepicker.parseDate(format, rawValue);

                            args.altField = '#' + target;
                            args.altFormat = format;
                        }

                        self[type](args);
                        self.data('val.type', type);

                        if (type == "multiDatesPicker") {
                            if (value) {
                                self.multiDatesPicker('addDates', value);
                            }
                            var disallowed = self.data('disallowed');
                            if (disallowed) {
                                self.multiDatesPicker('addDates', disallowed.split(','), 'avoided');
                            }
                        } else {
                            self.datepicker('setDate', value);
                            var allowedRaw = self.data('allowed');
                            if (allowedRaw !== undefined) {
                                var allowed = allowedRaw.split(',');
                                $('.inline-calendar').datepicker('option', 'beforeShowDay', function (date) {
                                    var format = $.datepicker.formatDate('yy-mm-dd', date);
                                    return [$.inArray(format, allowed) >= 0 ? true : false, ''];
                                });
                            }
                        }
                        self.datepicker('refresh');
                    });
                };
                window.checkForCalendars();
            };

这样打电话:

$(document).ready(function () {
    multiDatesPickerBinding();

});

0 个答案:

没有答案