我正在使用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 :(得分:0)
为了获取asp.net元素的客户端元素ID,您需要使用ClientID
属性,如下所示:
<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>
答案 1 :(得分: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;
}
}