CalendarExtender更改日期的JavaScript [英] CalendarExtender Change date with Javascript
问题描述
我有我的网页上CalendarExtender控制,有时将日期改到下发生的历史星期天。我目前使用的控制的OnClientDateSelectionChanged属性来调用一个函数,将一些日子添加到日起至其周日。
I have a CalendarExtender control on my page and sometimes have to change the date to the next occuring Sunday. I'm currently using the OnClientDateSelectionChanged property of the control to call a function that will add some days to the date until its Sunday.
我遇到的问题是,如果我在我的日历中选择一个周二,文本框会显示下周日,但在日历中选择的日期仍然是周二。
The problem I'm having is that if I select a Tuesday in my calendar, the textbox will display the next Sunday but the selected date in the calendar is still Tuesday.
我如何更新CalendarExtender有有一个我在JavaScript中选择了新的日期?文本框中的CalendarExtendar连接到显示正确的日期......
How do I update the CalendarExtender to have the new date that has one I selected in javascript? The textbox the CalendarExtendar is connected to shows the correct date...
推荐答案
更改文本框是在的TargetControlID 的值在 CalendarExtender 会影响到选择日期的,如果以下两个条件都满足:
Changing the value of the textbox that is the TargetControlId for the CalendarExtender affects the selected date if the following 2 conditions are met:
- 的的onchange 事件触发的文本框(通过手动更改文本,或通过调用一个明确的JavaScript fireEvent()方法。
- 在格式在文本框中输入的日期所用的CalendarExtender控制相同的格式相匹配。
- An onchange event is fired on the textbox (either by changing the text manually or by calling an explicit javascript fireEvent() method.
- The format of the date entered in the textbox matches the same format used by the CalendarExtender control.
话虽这么说,正确的方式来处理,这是调用CalendarExtender控制的 set_selectedDate()
功能。这一次通话,不仅将所选择的日历上,而且在同一时间有针对性的文本框。
That being said, the correct way to handle this is to call the set_selectedDate()
function of the CalendarExtender control. This one call, not only sets the selected on the Calendar, but also on the Targeted textbox at the same time.
下面的例子code:
<cc1:CalendarExtender ID="CalendarExtender1" runat="server"
OnClientDateSelectionChanged="dateSelectionChanged"
TargetControlID="txtDate" PopupButtonID="imgCalendar">
</cc1:CalendarExtender>
<script type="text/javascript">
function dateSelectionChanged(sender, args){
selectedDate = sender.get_selectedDate();
/* replace this next line with your JS code to get the Sunday date */
sundayDate = getSundayDateUsingYourAlgorithm(selectedDate);
/* this sets the date on both the calendar and textbox */
sender.set_SelectedDate(sundayDate);
}
</script>
这篇关于CalendarExtender更改日期的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!