【问题标题】:Javascript NoGray Calendar not working with blocked dates using this.is_selectable() with onDateClick or onSelectJavascript NoGray 日历无法使用 this.is_selectable() 和 onDateClick 或 onSelect 处理被阻止的日期
【发布时间】: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


    【解决方案1】:

    is_selectable 方法返回一个数组,其中第一个索引是真或假,第二个是原因。你可以在这里找到文档http://www.nogray.com/api/calendar/is_selectable.php

    在您的代码中,您可以将if (this.is_selectable(dt)){ 更改为if (this.is_selectable(dt)[0]){

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-17
      • 2011-09-25
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      相关资源
      最近更新 更多