如何使用ajax控制套件从当前日期选择三个日期之后的日期

问题描述 投票:0回答:1

如何从AJAX控制套件中的当前日期(今天)开始三天之后禁用所有将来的日期

         <asp:TextBox ID="txtEndDate" runat="server" class="form-control"
                required="This Field is Required" AutoComplete="off"></asp:TextBox>                                                            

        <ajaxToolkit:CalendarExtender ID="CalendarExtender2" 
    runat="server" OnClientDateSelectionChanged="checkProjectEndDate"
 TargetControlID="txtEndDate" Format="dd-MMM-yyyy"></ajaxToolkit:CalendarExtender>



<script type="text/javascript">
     function checkProjectEndDate(sender, args) {
     if (sender._selectedDate >= new Date()) {
     alert("You can not select a future date than today!");
     sender._selectedDate = new Date();
     sender._textbox.set_Value(sender._selectedDate.format(sender._format))
       }
      }
</script>

它不允许选择今天的将来日期,但是我想从今天起选择三天,让我解释一下,我希望用户在以后的三天后不能选择任何未来的日期,假设今天是01-11-2019,所以我的日历显示仅显示03-11-2019 3Nov之后,所有日期均不可见

javascript html asp.net ajaxcontroltoolkit
1个回答
0
投票

选择大于3天的日期:

var date = new Date();
date.setDate(date.getDate() + 3);
if(selected_date > date){
   // code here
}

© www.soinside.com 2019 - 2024. All rights reserved.