我使用datepicker.setdefaults为datepicker添加了一个自定义按钮 一切正常,但唯一的问题是当用户从键盘输入日期时,日期选择器上的自定义按钮栏消失。有人可以提供帮助。以下是代码。
$。datepicker.setDefaults({ firstDay:1, changeMonth:是的, changeYear:true, showOtherMonths:真实, selectOtherMonths:真实, showButtonPanel:是的, maxDate:新日期(' 12/26/9999'),
beforeShow: function( input ) {
setTimeout(function() {
var buttonPane = $( input )
.datepicker( "widget")
.find( ".ui-datepicker-buttonpane" );
var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">End of Time</button>');
btn.unbind("click").bind("click", function() {
$(input).datepicker('setDate', new Date(endOfTime));
// $(input).datepicker('hide');
$(input).trigger('change');
});
btn.appendTo( buttonPane );
}, 0);
},
onChangeMonthYear: function( year, month, instance ) {
setTimeout(function() {
var buttonPane = $( instance.input )
.datepicker( "widget" )
.find( ".ui-datepicker-buttonpane" );
var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">End of Time</button>');
btn.unbind("click").bind("click", function() {
$(instance.input).datepicker('setDate', new Date(endOfTime));
// $(instance.input).datepicker('hide');
$(instance.input).trigger('change');
});
btn.appendTo( buttonPane );
}, 0 );
}
});