javascript - 使用 jQuery UI 将特定日期变灰不起作用
问题描述
使用下面的代码,我试图将 21/12/2020 显示为灰色,因为我们要到星期二(2020 年 12 月 22 日)才会发货。我在下面的代码中找不到什么问题。请指出代码中可能导致它无法工作的错误。
<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>
解决方案
根据 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>
推荐阅读
- tkinter - 如何在我的游戏中添加屏幕计时器?
- javascript - 自定义模块中的 EventEmitter 抛出“.on(...) 不是函数”
- swift - 使用 Swift 进行 Cocoa 打印:“任何”打印机设置的边距/页面大小不规则,有什么解决方法吗?
- azure - 如何从 wwwroot azure app services 下创建的子文件夹启动我的应用程序
- firebase - Firebase 功能:无法加载默认凭据
- git - SourceTree中的提交太多,如何删除它们?
- boost - moodle左侧的块
- firebase - 即使文档字段在 Firestore 安全规则中不可用,如何允许访问?
- php - 在 WooCommerce 中将特定产品添加到购物车之前清空购物车
- java - DatainputStream的readUTF()方法,单独读取文本数据,会报EOF异常。为什么?