dhtmlgoodies_calendar.js不适用于Firefox和Chrome
本文关键字:Firefox Chrome 适用于 不适用 calendar js dhtmlgoodies | 更新日期: 2023-09-27 18:23:52
我的asp.net应用程序中有一个dhtmlgooies_calendar,并对writeCalendarContent方法进行了一些更改,以禁用过去的日期。它在Internet explorer上运行良好。但在firefox和chrome中,过去的日期仍然显示在屏幕上。
有人知道如何在那些Brower里做到这一点吗?任何帮助都将不胜感激。感谢
这是我的方法:
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++;
它只为当前日期和下一个日期添加单击事件。它不会为过去的日期添加点击。您可以添加过去日期的样式(添加非活动日期类的样式)。
一点也不,下面的代码是正确的,并且经过了测试
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';
}