我在asp.net应用程序中有一个dhtmlgoodies_calendar,并且对writeCalendarContent方法进行了一些更改以禁用过去的日期。它在Internet Explorer上运行良好。但是在Firefox和Chrome中,过去的日期仍然会显示。
是否有人对如何在这些浏览器中进行这项工作有任何想法?
任何帮助表示赞赏。
谢谢
这是我的方法:
function writeCalendarContent()
{
var blockDateInPast = true;
var calendarContentDivExists = true;
if(!calendarContentDiv){
calendarContentDiv = document.createElement('DIV');
calendarDiv.appendChild(calendarContentDiv);
calendarContentDivExists = false;
}
currentMonth = currentMonth/1;
var d = new Date();
var data = new Date();
var AnoAtual = data.getYear();
var MesAtual = data.getMonth();
var DiaAtual = data.getDate();
d.setFullYear(currentYear);
d.setDate(1);
d.setMonth(currentMonth);
var dayStartOfMonth = d.getDay();
if (! weekStartsOnSunday) {
if(dayStartOfMonth==0)dayStartOfMonth=7;
dayStartOfMonth--;
}
document.getElementById('calendar_year_txt').innerHTML = currentYear;
document.getElementById('calendar_month_txt').innerHTML = monthArray[currentMonth];
document.getElementById('calendar_hour_txt').innerHTML = currentHour;
document.getElementById('calendar_minute_txt').innerHTML = currentMinute;
var existingTable = calendarContentDiv.getElementsByTagName('TABLE');
if(existingTable.length>0){
calendarContentDiv.removeChild(existingTable[0]);
}
var calTable = document.createElement('TABLE');
calTable.width = '100%';
calTable.cellSpacing = '0';
calendarContentDiv.appendChild(calTable);
var calTBody = document.createElement('TBODY');
calTable.appendChild(calTBody);
var row = calTBody.insertRow(-1);
row.className = 'calendar_week_row';
if (showWeekNumber) {
var cell = row.insertCell(-1);
cell.innerHTML = weekString;
cell.className = 'calendar_week_column';
cell.style.backgroundColor = selectBoxRolloverBgColor;
}
for(var no=0;no<dayArray.length;no++){
var cell = row.insertCell(-1);
cell.innerHTML = dayArray[no];
}
var row = calTBody.insertRow(-1);
if (showWeekNumber) {
var cell = row.insertCell(-1);
cell.className = 'calendar_week_column';
cell.style.backgroundColor = selectBoxRolloverBgColor;
var week = getWeek(currentYear,currentMonth,1);
cell.innerHTML = week; // Week
}
for(var no=0;no<dayStartOfMonth;no++){
var cell = row.insertCell(-1);
cell.innerHTML = ' ';
}
var colCounter = dayStartOfMonth;
var daysInMonth = daysInMonthArray[currentMonth];
if(daysInMonth==28){
if(isLeapYear(currentYear))daysInMonth=29;
}
for(var no=1;no<=daysInMonth;no++){
d.setDate(no-1);
if(colCounter>0 && colCounter%7==0){
var row = calTBody.insertRow(-1);
if (showWeekNumber) {
var cell = row.insertCell(-1);
cell.className = 'calendar_week_column';
var week = getWeek(currentYear,currentMonth,no);
cell.innerHTML = week; // Week
cell.style.backgroundColor = selectBoxRolloverBgColor;
}
}
var cell = row.insertCell(-1);
if (currentYear<AnoAtual && blockDateInPast==true)
{
cell.className='DesactiveDay';
cell.onclick = null;
}
else if (currentYear==AnoAtual)
{
if (currentMonth < MesAtual && blockDateInPast == true)
{
cell.className='DesactiveDay';
cell.onclick = null;
}
else if (currentMonth==MesAtual)
{
if (no < DiaAtual && blockDateInPast == true)
{
cell.className='DesactiveDay';
cell.onclick = null;
}
else
{
cell.onclick = pickDate;
}
}
else
{
cell.onclick = pickDate;
}
}
else
{
cell.onclick = pickDate;
}
if (cell.onclick == pickDate)
{
if(currentYear==inputYear && currentMonth == inputMonth && no==inputDay){
cell.className='activeDay';
cell.onclick = pickDate;
}
}
cell.innerHTML = no;
colCounter++;
}
if(!document.all){
if(calendarContentDiv.offsetHeight)
document.getElementById('topBar').style.top = calendarContentDiv.offsetHeight + document.getElementById('timeBar').offsetHeight + document.getElementById('topBar').offsetHeight -1 + 'px';
else{
document.getElementById('topBar').style.top = '';
document.getElementById('topBar').style.bottom = '0px';
}
}
if(iframeObj){
if(!calendarContentDivExists)setTimeout('resizeIframe()',350);else setTimeout('resizeIframe()',10);
}
}
最佳答案
只需在writeCalendarContent()
的末尾添加以下代码,
if(currentYear==inputYear && currentMonth == inputMonth && no==inputDay){
cell.className='activeDay';
cell.onclick = pickDate;
}
else if(currentYear<inputYear || currentMonth < inputMonth || no<inputDay){
cell.className = 'inactive-date';
}
else{
cell.onclick = pickDate;
}
cell.innerHTML = no;
colCounter++;
它仅针对当前日期和下一个日期添加单击事件。它不会为过去的日期添加点击。您可以为过去的日期添加样式(为非活动日期类添加样式)。
关于c# - dhtmlgoodies calendar.js不适用于Firefox和Chrome,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9198214/