我有一个内联的DatePicker(Week-Picker),如下所示,它在Select上触发ASP.NET单击事件。它运行正常,我的ASP代码是它的一部分,但是如果我选择日期为ex:在按DatePicker的next / prev按钮推进月份后,当页面在回发后刷新时,DatePicker将返回当前月份...它会在selectCurrentWeek()方法中丢失所选的startDate / endDate范围。
var startDate;
var endDate;
var selectCurrentWeek = function () {
window.setTimeout(function () {
$('.week-picker').find('.ui-datepicker-current-day a').addClass('ui-state-active')
}, 1);
}
$('.week-picker').datepicker({
showOtherMonths: true,
selectOtherMonths: true,
firstDay: 1,
onSelect: function (dateText, inst) {
var date = $(this).datepicker('getDate');
startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 1);
endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 6);
var dateFormat = inst.settings.dateFormat || $.datepicker._defaults.dateFormat;
$('#txtDP1').val($.datepicker.formatDate(dateFormat, date, inst.settings));
selectCurrentWeek();
DP1_Submit();
},
beforeShowDay: function (date) {
var cssClass = '';
if (date >= startDate && date <= endDate)
cssClass = 'ui-datepicker-current-day';
return [true, cssClass];
},
onChangeMonthYear: function (year, month, inst) {
selectCurrentWeek();
}
});
$('.week-picker .ui-datepicker-calendar tr').live('mousemove', function () { $(this).find('td a').addClass('ui-state-hover'); });
$('.week-picker .ui-datepicker-calendar tr').live('mouseleave', function () { $(this).find('td a').removeClass('ui-state-hover'); });
隐藏字段/按钮是:
<asp:TextBox ID="txtDP1" runat="server" style="display:none;" />
<asp:Button ID="btnDP1" runat="server" Text="Go" style="display:none;" />
我尝试过使用setDate()方法和defaultDate属性但没有成功。救命?
答案 0 :(得分:0)
使用隐藏字段而不是文本框。由于style =“display:none;”而丢失的值在文本框中。
<asp:HiddenField id="txtDP1" value="" runat="server"/>