onSelect不绑定第一次加载

下面提到的方法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(); });