如何禁用默认DHTML日历中的前几天

How to disable previous days in default DHTML calendar?

本文关键字:前几天 日历 DHTML 何禁用 默认      更新时间:2023-09-26

如何在默认DHTML日历中禁用前几天?

我使用了下面的代码,
<script type="text/javascript">
 Calendar.setup({
        inputField : '_dob',
        ifFormat : '%m/%e/%y',
        button : '_dob_trig',
        align : 'Bl',
        singleClick : true,
      disableFunc: function(date) {
          var now= new Date();
        return (date.getTime() < now.getTime());
    }
    });
</script>

它可以禁用以前的日期。但当我们选择有效日期时,什么都不会发生。日期没有被添加到日历的文本字段中。

如果我更改月份并返回,我可以选择日期!

任何想法?

哇!

可能是javascript错误。除非从下个月开始往返,否则我无法选择任何日期。

我通过一些if循环来绕过它。我更新的代码如下:

<script type="text/javascript">
 Calendar.setup({
        inputField : '_dob',
        ifFormat : '%m/%e/%y',
        button : '_dob_trig',
        align : 'Bl',
        singleClick : true,
        disableFunc: function(date) {
          var now= new Date();
        if(date.getFullYear()<now.getFullYear())
        {
            return true;
        }
        if(date.getFullYear()==now.getFullYear())
        {
            if(date.getMonth()<now.getMonth())
            {
                return true;
            }
        }
        if(date.getMonth()==now.getMonth())
        {
            if(date.getDate()<now.getDate())
            {
                return true;
            }
        }
    },
    });
</script>

我有同样的问题,调试后,问题似乎是日历无法找出当前日历日期应该是什么(因为它被禁用了disableFunc回调函数)。你有两个选择。

  1. 确保disablefunction函数对当前日期返回false。这样它就不会在日历中被禁用,并且会正常工作。
  2. 你可以在calendar.js中if (!cell.disabled)行之后添加以下行。(这恰好是我的文件版本- v1.51中的第1183行)

    其他{这一点。currentDateEl = cell;}

第二个选项将允许您禁用当前日期。

对于那些想知道这个DHTML日历是什么,这里有一个链接到它的文档:http://www.dni.ru/js/doc/html/reference.html

Disable Function应该总是返回TRUE或FALSE。

disablefunction function:一个接收JS Date对象的函数。如果该日期必须被禁用,它应该返回true,否则返回false。

请参考以下内容,

日历设置参考

但是在你的代码禁用函数返回什么…(所以它进入js错误,没有任何工作在事件点击..

检查你的情况,

return (date.getDate() <= now.getDate());

检查上述条件后,根据需要返回true或false…

试试下面的代码

 Calendar.setup({
            inputField : '_dob',
            ifFormat : '%m/%e/%y',
            button : '_dob_trig',
            align : 'Bl',
            singleClick : true,
            dateStatusFunc :    function (date) { 
                var now= new Date();
                return (date.getDate() <= now.getDate());
            }
        });