【发布时间】:2013-05-03 00:09:07
【问题描述】:
我有一个带有TextBox 和CalendarExtender 的页面,应该可以让我检测选择的日期。但是,这是报告未选择的日期。
<asp:TextBox ID="tbEffectiveDate" runat="server"
CssClass="input-small"
MaxLength="10"
Text='<%# Bind("NewEffectiveDate", "{0:MM/dd/yyyy}") %>'>
</asp:TextBox>
<ajaxToolkit:CalendarExtender ID="atkEffectiveDate" runat="server"
FirstDayOfWeek="Sunday"
TargetControlID="tbEffectiveDate"
Format="MM/dd/yyyy"
OnClientDateSelectionChanged="CheckForSunday">
</ajaxToolkit:CalendarExtender>
基本上我是在确保用户选择了星期天,但是当我在日历上选择一天时,JavaScript 会说它是前一天。我很困惑。
function CheckForSunday(sender, args) {
var selectedDate = new Date();
selectedDate = sender.get_selectedDate();
// Both of these show the date before the date was selected
alert(sender.get_selectedDate());
if (selectedDate.getDay() != 0) {
// not a Sunday
var sunday = selectedDate;
// calculated the nearest Sunday
sunday.setDate(selectedDate.getDate() - selectedDate.getDay());
sender.set_selectedDate(sunday);
// tell the user that the date wasn't a Sunday
// and that the previous Sunday was selected.
$("#must-be-sunday").modal("show");
}
}
例如,如果我选择一个星期日,比如 5 月 5 日:
然后在alert(sender.get_selectedDate());这一行显示
这表示选择了 5 月 4 日星期六而不是 5 月 5 日。由于在我的语言环境中,我们是 -0700,并且显示的是 5 日午夜前 7 小时,我猜这与时区有关。
有谁知道可能导致此问题的原因以及如何解决它,使其不适用于时间和仅选择的日期?
【问题讨论】:
标签: javascript asp.net ajaxcontroltoolkit ajax.net