0
有誰知道如何從使用JavaScript的RadDateTimePicker中的當前日期扣除7天?從RadDateTimePicker扣除天
我沒有找到任何關於如何從RadDateTimePicker中扣除天數的例子。
如果有人能給我看例子,我會很樂意。
Aspx.code
<table border="0">
<tr>
<td>From:</td>
<td>
<telerik:RadDateTimePicker ID="rdpDateFrom" runat="server" Enabled="True" Width="170px">
<Calendar ID="fromCalendar" runat="server" EnableKeyboardNavigation="True">
<SpecialDays>
<telerik:RadCalendarDay Repeatable="Today" ItemStyle-BackColor="lightblue"></telerik:RadCalendarDay>
</SpecialDays>
</Calendar>
<DateInput ID="DateInput3" ToolTip="From Date input" runat="server"/>
</telerik:RadDateTimePicker>
</td>
</tr>
<tr>
<td>To:</td>
<td>
<telerik:RadDateTimePicker ID="rdpDateTo" runat="server" Enabled="True" Width="170px">
<Calendar ID="toCalendar" runat="server" EnableKeyboardNavigation="True" />
<DateInput ID="DateInput4" ToolTip="To Date input" runat="server"/>
</telerik:RadDateTimePicker>
</td>
</tr>
</table>
JavaScript代碼
function OnClientSelectedIndexChanged(sender, eventArgs) {
var range = $find("<%= rcbDateTime.ClientID %>");
var item = eventArgs.get_item();
var From = $find("<%= rdpDateFrom.ClientID %>");
var To = $find("<%= rdpDateTo.ClientID %>");
var todaysDate = new Date();
todaysDate.setDate(todaysDate.getDate());
if (item.get_value() == "1") { //Today's Date
From.set_selectedDate(todaysDate);
To.set_selectedDate(todaysDate);
}
if (item.get_value() == "2") { //Last 7 days
//Calculation
From.set_selectedDate(
To.set_selectedDate(todaysDate);
}
}
'todaysDate.setDate(todaysDate.getDate());'就像說'x = x',它不會改變* todaysDate *的值。如果你想在7天前設置一個日期,那麼'var weekAgo = new Date(+ todaysDate); weekAgo.setDate(weekAgo.getDate() - 7);'。 – RobG 2014-08-28 23:01:42
我試了一下我收到了長號碼功能 var todaysDate = new Date(); if(item.get_value()==「2」){// Last 7 days // Calculation var weekAgo = new Date(+ todaysDate); var result = weekAgo.setDate(weekAgo.getDate() - 7); From.setDate(result); To.set_selectedDate(todaysDate); } } – 2014-08-28 23:21:59