【发布时间】:2014-07-25 13:07:29
【问题描述】:
我之前在Javascript NoGray Calendar find next available date after chosen blocked dates if today is blocked 这个位置问过一个类似的问题,以检查单个日历。现在对于第二个日历,我试图让它检查 my_cal1 的前一个日期,添加我选择为 7 天的天数,然后检查该日期是否可用,如果不做同样的事情第一个日历通过每天检查直到它可用的日期,然后选择该日期。所以要明确一点,从第一个日历选择日期开始的天数不是完全固定的,只有当它选择的日期可用时,它才会移动到下一个可用日期。
这是我目前正在尝试的代码。这是我要解决的第二个 onLoad,即日历 2 my_cal2 的 onLoad:
my_cal1 = new ng.Calendar({
input: {date:'date1', month:'month1', year:'year1'},
selected_date:new Date(),
display_date:new Date(),
dates_off:[{date:1, month:0},{date:25, month:11},{date:24, month:6, year:2014},{date:27, month:6, year:2014},{date:28, month:6, year:2014},{date:29, month:6, year:2014},{date:30, month:6, year:2014},{date:31, month:6, year:2014},{date:8, month:7, year:2014},{date:9, month:7, year:2014}],
events: {
onDateClick: function(dt){
this.select_date(dt);
},
// code to check if the start date is selectable
onLoad: function(){
var st_dt = this.get_start_date().clone();
while(!this.is_selectable(st_dt)[0]){
st_dt = st_dt.from_string('today + 1');
}
// checking if no dates are selected
if (!ng.defined(this.get_selected_date())){
this.select_date(st_dt);
}
this.set_start_date(st_dt);
}
}
});
my_cal2 = new ng.Calendar({
input: {date:'date1', month:'month1', year:'year1'},
selected_date:new Date(),
display_date:new Date(),
dates_off:[{date:1, month:0},{date:25, month:11},{date:24, month:6, year:2014},{date:27, month:6, year:2014},{date:28, month:6, year:2014},{date:29, month:6, year:2014},{date:30, month:6, year:2014},{date:31, month:6, year:2014},{date:8, month:7, year:2014},{date:9, month:7, year:2014}],
events: {
onDateClick: function(dt){
this.select_date(dt);
},
// code to check if the start date is selectable
onLoad: function(){
var st_dt = this.get_start_date().clone();
console.log(this.is_selectable(st_dt)[0]);
while(!this.is_selectable(st_dt)[0])
{
st_dt = st_dt.from_string('today + 1');
}
// checking if no dates are selected
if (!ng.defined(this.get_selected_date()))
{
var stt_dt = this.select_date(st_dt.from_string('today + 7')).clone();
console.log(this.is_selectable(stt_dt)[0]);
while(!this.is_selectable(stt_dt)[0])
{
stt_dt = stt_dt.from_string('today + 1');
}
if (!ng.defined(this.get_selected_date(stt_dt)))
{
this.select_date(stt_dt);
}
}
this.set_start_date(stt_dt);
}
}
});
任何帮助将不胜感激。提前致谢。
更新:
我尝试使用 my_cal2.get_selected_date():
onLoad: function()
{
var theDate = my_cal1.get_start_date();
theDate = theDate.from_string('today + 7');
var st_dt = theDate.clone();
console.log(this.is_selectable(st_dt)[0]);
while(!this.is_selectable(st_dt)[0])
{
st_dt = st_dt.from_string('today + 1');
}
// checking if no dates are selected
if (!ng.defined(this.get_selected_date()))
{
this.select_date(st_dt);
}
this.set_start_date(st_dt);
},
这可行,但现在之前的所有日期都不可用,即使它们没有被阻止,而且当您使用 get_day_since 查看两个日期之间的差异时,它也无法正常工作。
仍然需要帮助。谢谢。
【问题讨论】:
标签: javascript php jquery date calendar