dhtmlgoodies calendar.js不适用于Firefox和Chrome

时间:2012-02-08 17:16:04

标签: c# javascript asp.net .net

我的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 = '&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 个答案:

答案 0 :(得分: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 :(得分: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';
    }