【发布时间】:2014-09-22 15:45:27
【问题描述】:
我在使用带有 this.is_selectable() 的 onDateClick 选择的 NoGray 日历时遇到问题。可以在http://www.nogray.com/calendar.php 找到日历。我遇到的问题是,最初,当我在已选择的日历中重新选择一个日期时,它取消了选择它,但使用这个修复了:
onDateClick: function(dt)
{
this.select_date(dt);
}
我从Javascript Calendar deselecting date when date is selected again instead of reselecting it 发布的答案中得到了这个修复,除了现在,如果日期被阻止,它不会在日历中选择它,但从技术上讲,它会选择它,因为它仍然显示在以下脚本仅在日期可选且未被阻止时才通过。
我的代码如下:
<select id="date1"></select>
<select id="month1"></select>
<select id="year1"></select>
<select id="date2"></select>
<select id="month2"></select>
<select id="year2"></select>
<script src="PATH/TO/ng_all.js" type="text/javascript"></script>
<script src="PATH/TO/components/calendar.js" type="text/javascript"></script>
<script type="text/javascript">
var my_cal1, my_cal2;
ng.ready(function(){
my_cal1 = new ng.Calendar({
input: {date:'date1', month:'month1', year:'year1'},
selected_date:new Date(),display_date:new Date(),
dates_off:[{date:21, month:7, year:2014}],
events:
{
onDateClick: function(dt)
{
if (this.is_selectable(dt)){
this.select_date(dt);
var dt2 = my_cal2.get_selected_date();
if ((ng.defined(dt2)) && (dt2 != ""))
{
theoutputtext=dt2.get_day_since(dt);
}
}
}
}
});
my_cal2 = new ng.Calendar({
input: {date:'date2', month:'month2', year:'year2'},
dates_off:[{date:21, month:7, year:2014}],
events:
{
onDateClick: function(dt)
{
if (this.is_selectable(dt)){
this.select_date(dt);
var dt1 = my_cal1.get_selected_date();
if ((ng.defined(dt1)) && (dt1 != ""))
{
theoutputtext=dt.get_day_since(dt1);
}
}
}
}
});
});
</script>
“this.is_selectable()”if 语句有问题,因为无论日期是否被阻止,它都会将其传递为 true。
我已经用“onSelect”、“onDateClick”和它自己尝试过这个,但这似乎仍然不起作用。
如何解决这个问题,以便当日期被阻止时,它不会将日期传递到日历和“输出文本”,并且如果用户选择了一个已经选择的日期并且仍然可以工作不会像没有“this.select_date(dt)”部分那样取消选择它吗?
提前感谢您的帮助。
【问题讨论】:
标签: javascript jquery validation date calendar