2012-02-08 78 views
0

我的asp.net应用程序中有一个dhtmlgoodies_calendar,并对writeCalendarContent方法进行了一些更改以禁用过去的日期。它在Internet Explorer上正常工作。但是在Firefox和Chrome中,过去的日期仍然显示出来。dhtmlgoodies_calendar.js不适用于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 = '&nbsp;'; 
    } 

    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); 
    } 




} 

回答

2

只是在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++; 

它添加了click事件只为当前日期和未来日期。它不会为过去的日期添加点击。您可以为过去的日期添加样式(为非活动日期类添加样式)。

1

根本不是,这下面的代码是正确的和测试

if(disabledDateInPast){ 
     var now = new Date(); 
     var yearOfNow = now.getFullYear(); 
     var monthOfNow = now.getMonth(); 
     var noOfNow = now.getDate(); 

     if(currentYear < yearOfNow){ 
      cell.className = 'desactiveDay'; 
     } 
     else if(currentYear > yearOfNow){ 
      cell.onclick = pickDate; 
     } 
     else if (currentYear == yearOfNow){ 
      if(currentMonth < monthOfNow){ 
       cell.className = 'desactiveDay'; 
      } 
      else if(currentMonth > monthOfNow){ 
       cell.onclick = pickDate; 
      } 
      else if(currentMonth == monthOfNow){ 
       if(no < noOfNow){ 
       cell.className = 'desactiveDay'; 
       } 
       else{ 
        cell.onclick = pickDate; 
       } 
      } 
     } 
    } 
    else{ 
     cell.onclick = pickDate; 
    } 

    if(currentYear==inputYear && currentMonth == inputMonth && no==inputDay){ 
     cell.className='activeDay'; 
    } 
相关问题