2010-10-23 156 views
0

我有Ajax日曆,並且我想阻止用戶選擇日期(今天或將來的日期)我有java腳本代碼但是當我阻止我選擇日期早於(10-10-1990) 。任何人都可以幫助我。在Ajax日曆中格式化日期

的Javascript

<script type="text/javascript"> 
     function checkDate(sender,args) 
{ 
if (sender._selectedDate < new Date()) 
      { 
       alert("You cannot select a day earlier than today!"); 
       sender._selectedDate = new Date(); 
       // set the date back to the current date 
sender._textbox.set_Value(sender._selectedDate.format(sender._format)) 
      } 
} 
    </script> 

ASPX

<table> 
<tr> 
    <td class="bod_d_reg_txt_p lm7"> Birth year : </td> 
    <td colspan="3"><asp:TextBox ID="TXTBirthdate" runat="server" Width="150px" ReadOnly="True"></asp:TextBox> 
     <label> 
      <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TXTBirthdate" 
                      OnClientDateSelectionChanged="checkDate" PopupButtonID="Image1"> </cc1:CalendarExtender> 
      <asp:Image ID="Image1" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png" /> 
     </label> 
     <asp:CompareValidator ID="cmp" ControlToValidate="TXTBirthdate" runat="server" ErrorMessage="*" 
                     Operator="LessThanEqual" Type="Date" Display="Dynamic">*</asp:CompareValidator> 
     <br /> 
     <span style="font-family: 'MS SystemEx'; color: #C0C0C0">(Click the image button to 
     show the calendar to choose your date) </span></td> 
</tr> 
</table> 

回答

0

你不應該依賴於JavaScript來驗證您的輸入。請使用您的應用程序端點來執行此操作。另外,你可能想用jQuery來實現你想要的東西。

0

如何:

var today = new Date(); 
today.setDate(today.getDate() - 1); 

if(sender._selectedDate < today) {  
}