2014-03-28 109 views
0

我正在使用ajax工具包日曆擴展控件每次顯示僅選擇星期五

在日曆中,我只想顯示星期五我不想顯示其他日子。任何幫助深表感謝。

我試過了。

<script type="text/javascript"> 
    function checkdate(txt) { 
     var seldate = document.getElementById("txtDate") 
     var selectedDate = new Date(seldate.value); 
     var today = new Date(); 
     var weekday = new Array(7); 
     weekday[0] = "Sunday"; 
     weekday[1] = "Monday"; 
     weekday[2] = "Tuesday"; 
     weekday[3] = "Wednesday"; 
     weekday[4] = "Thursday"; 
     weekday[5] = "Friday"; 
     weekday[6] = "Saturday" 
     if (selectedDate != weekday[5]) { 
      alert('Select Friday only !'); 
      var a = document.getElementById("txtDate"); 
      a.value = " "; 
     } else { 
      if (selectedDate == weekday[5]) { 
       var a = document.getElementById("txtDate"); 
       a.value = selectedDate; 
      }   
     } 
    } 

</script> 

<asp:TextBox ID="txtDate" Enabled="true" runat="server" Width="200px" onchange="checkdate(this);"></asp:TextBox> 

<ajaxtK:CalendarExtender ID="calext" runat="server" TargetControlID="txtDate" ></ajaxtK:CalendarExtender> 

回答

0

爲了得到你需要使用ClientID屬性這樣一個asp.net元素的客戶端元素ID:

<script type="text/javascript"> 
    function checkdate(txt) { 
     var seldate = document.getElementById("<%= txtDate.ClientID %>") 
     var selectedDate = new Date(seldate.value); 
     var today = new Date(); 
     var weekday = new Array(7); 
     weekday[0] = "Sunday"; 
     weekday[1] = "Monday"; 
     weekday[2] = "Tuesday"; 
     weekday[3] = "Wednesday"; 
     weekday[4] = "Thursday"; 
     weekday[5] = "Friday"; 
     weekday[6] = "Saturday" 
     if (selectedDate.getDay() != weekday[5]) { //add getDay() 
      alert('Select Friday only !'); 
      var a = document.getElementById("<%= txtDate.ClientID %>"); 
      a.value = " "; 
     } else { 
      var a = document.getElementById("<%= txtDate.ClientID %>"); 
      a.value = selectedDate; 
     } 
    } 

</script> 

<asp:TextBox ID="txtDate" Enabled="true" runat="server" Width="200px" onchange="checkdate(this);"></asp:TextBox> 

<ajaxtK:CalendarExtender ID="calext" runat="server" TargetControlID="txtDate" ></ajaxtK:CalendarExtender> 
0

您在使用文本框的錯誤標識中獲取價值和 從你必須調用getDay()函數..下面的功能,將工作 使用日期對象獲得一天....

function checkdate() { 
     var seldate = document.getElementById("<%= txtDate.ClientID %>") 
     var selectedDate = new Date(seldate.value); 
     var today = new Date(); 
     var weekday = new Array(7); 
     weekday[0] = "Sunday"; 
     weekday[1] = "Monday"; 
     weekday[2] = "Tuesday"; 
     weekday[3] = "Wednesday"; 
     weekday[4] = "Thursday"; 
     weekday[5] = "Friday"; 
     weekday[6] = "Saturday" 
     if (weekday[selectedDate.getDay()] != weekday[5]) { 
      alert('Select Friday only !'); 
      var a = document.getElementById("<%= txtDate.ClientID %>"); 
      a.value = " "; 
     } else { 

       alert('Great , you have selected Friday!'); 
       var a = document.getElementById("<%= txtDate.ClientID %>"); 
       a.value = selectedDate; 

     } 
    } 
相關問題