如何在ajax日历扩展器中禁用周末?

时间:2013-11-11 05:54:35

标签: asp.net

我已经实现了以下代码:此函数不能调用

我的Html代码是:

<asp:CalendarExtender ID="CalendarExtender1" runat="server" Format="dd/MM/yy" PopupButtonID="ImageButton1" PopupPosition="BottomRight" Enabled="true" OnClientDateSelectionChanged="DisableWeekends" TargetControlID="txtStartDate">

onclientshown=`"DisableWeekends"

功能如下:

function DisableWeekends(sender, args) {
  for (var i = 0; i < sender._days.all.length; i++) {
    for (var j = 0; j < 6; j++) {
      if (sender._days.all[i].id == "DisabledWeekendsCalendar" + j + "_5") {
        sender._days.all[i].disabled = true;
        sender._days.all[i].innerHTML = 
               "<div>" + sender._days.all[i].innerText + "</div>";
      }

      if (sender._days.all[i].id == "DisabledWeekendsCalendar" + j + "_6") {
        sender._days.all[i].disabled = true;
        sender._days.all[i].innerHTML = 
               "<div>" + sender._days.all[i].innerText + "</div>";
      }
    }
  }
}

2 个答案:

答案 0 :(得分:0)

试试这个

<script type="text/javascript">
        //disable sunday
        function detect_sunday(sender, args) {
            if (sender._selectedDate.getDay() == 0) {
                sender._selectedDate = new Date();
                // set the date back to the current date
                sender._textbox.set_Value(sender._selectedDate.format(sender._format));
                alert("You can't select sunday!");
            }
        }
    </script>

<asp:CalendarExtender ID="calenderExtender" runat="server" CssClass="cal_theme" TargetControlID="txtCalender"
            PopupButtonID="BtnCalender" OnClientDateSelectionChanged="detect_sunday"/>

答案 1 :(得分:0)

使用CSS

.DisableWeekends .ajax__calendar_days table tbody tr td:first-child
{

    text-decoration: line-through;
    color: red;
    pointer-events: none;
    cursor: default;
}

然后在DisableWeekends控制器中添加CalendarExtender类。