[英]Format date in Ajax calendar
我有Ajax日歷,我想阻止用戶選擇日期(今天或將來的日期),但我有Java腳本代碼,但是當我阻止我選擇早於(10-10-1990)的日期時,請提供任何幫助。
Java腳本
<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>
您不應該依賴javascript來驗證您的輸入。 請使用您的應用程序端點進行操作。 此外,您可能想例如使用jQuery來實現所需的功能。
怎么樣:
var today = new Date();
today.setDate(today.getDate() - 1);
if(sender._selectedDate < today) {
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.