简体   繁体   English

使用 jQuery UI 将特定日期灰显不起作用

[英]Graying out a specific date with jQuery UI doesn't work

With the code below, I'm trying to gray out 21/12/2020 because we don't ship until Tuesday(22/12/2020).使用下面的代码,我试图将 21/12/2020 显示为灰色,因为我们要到星期二(2020 年 12 月 22 日)才会发货。 I cannot find what is wrong in the code below.我在下面的代码中找不到什么问题。 Please point out the error in the code that might be causing it not to work.请指出代码中可能导致它无法工作的错误。

<script>
    jQuery(document).ready( function() {
        jQuery(function() {
            jQuery("#ship_date").datepicker( {
            var minDate;
                // get current date
                var d = new Date();
                var month = d.getMonth()+1;
                var day = d.getDate();
                var current_date = (month<10 ? '0' : '') + month + '/' + (day<10 ? '0' : '') + day + d.getFullYear() + '/'; 
    
                if (current_date < new Date(11, 22, 2020) {
                    minDate = new Date( 11, 22, 2020 );
                } else {
                    minDate = +1;
                }
                maxDate: '+2M',
                beforeShowDay: jQuery.datepicker.noWeekends
            } );
        });
    });
</script>

UPDATED the answer as per request from PKTG:根据 PKTG 的要求更新了答案:

<script>
      $( function() {
        var cuttoffdate = new Date(2020,11, 22);
        $( "#ship_date" ).datepicker(
        {
                    maxDate: '+2M',
                     beforeShowDay: function (date) {
                        show = true;
                        if (date.getDay() === 0 || date.getDay() === 6) { show = false; }
                        if(date<cuttoffdate) { show=false;};
                        var display = [show, '', (show) ? '' : 'Not available'];
                        return display;
                    }
                }
        );
      } );

</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM