My Calender code is
Calendar.setup ({
inputField : "date11", ifFormat : "%Y-%m-%d", showsTime : false, button : "date11_img"+t_i, singleClick : true, step : 1, dateStatusFunc : dateRange
});
Function
function dateRange(date)
{
var todaydate="";
var d = new Date(),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
todaydate= [year, month, day].join('-');
var splittoday = todaydate.split("-");
var m = Number(splittoday[1])-1;
var now = new Date(Number(splittoday[0]),Number(m),Number(splittoday[2]),0,0,0);
now.setDate(now.getDate());
return (date.getTime() > now.getTime());
}
I want to how to disable 2 different sets of dates . Currently i have disabled all the future dates .
Now i want to disable all past month dates for the same calender.
应该将两组不同的值传递给这个场景处理的对象。我已经调用了一个函数,但是我想再调用一个函数。需要方法来做那件事。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
To disable both future dates and all past month dates in your calendar, you can modify the dateRange
function to check for both conditions. You're already disabling future dates; to also disable all dates from previous months, you'll need to add a condition that checks if the given date is before the current month.
Here's how you can adjust your dateRange
function:
function dateRange(date) {
var d = new Date();
var currentDate = d.getDate();
var currentMonth = d.getMonth(); // Note: getMonth() returns 0-11, so no need to add 1 here for comparison
var currentYear = d.getFullYear();
// Check if the date is in the future
if (date.getFullYear() > currentYear ||
(date.getFullYear() === currentYear && date.getMonth() > currentMonth) ||
(date.getFullYear() === currentYear && date.getMonth() === currentMonth && date.getDate() > currentDate)) {
return false; // Disable future dates
}
// Check if the date is from a previous month
if (date.getFullYear() < currentYear ||
(date.getFullYear() === currentYear && date.getMonth() < currentMonth)) {
return false; // Disable dates from previous months
}
// If neither condition is met, the date is valid
return true;
}
This updated dateRange
function now disables both future dates and dates from any month prior to the current one. The function first checks if the date is in the future by comparing years, then months, and finally days if necessary. It then checks if the date belongs to a previous month based on the year and month alone. If either condition is met, it returns false
, effectively disabling those dates in your calendar.