disabledDate 应返回 false 表示可用、true 表示禁用;必须加 if(!date) return false; 防空值中断;仅用 date.getDay() 判断(0/6 为周末),禁用字符串匹配;min/max 与 disabledDate 可共用,但需注意格式和逻辑兜底。
禁用周一到周五以外的日期,本质就是只允许 date.getday() 返回值为 1~5 的日期。注意:js 中 getday() 返回 0 表示周日,1 是周一,5 是周五,6 是周六——别把 0 和 6 当成工作日。
必须加空值判断,否则 laydate 初始化时传入 null 或 undefined 会导致函数中断、日历无法展开:
if (!date) return false; —— 这行不能少true 表示禁用,false 或 undefined 表示可用return date.getDay() === 0 || date.getDay() === 6; 就能禁掉周末有人试图把 date 转成字符串再查星期几,比如 date.toString().includes('Mon') 或拼 date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate(),这会出问题:
toString() 格式不一致,includes('Mon') 在中文环境可能返回 '星期一',直接失效month 是 9 但没转成 '09'),导致 '2026-7-1' 和 '2026-07-01' 对不上disabledDate 每渲染一个格子就执行一次,几百次调用累积下来卡顿明显可以,而且常见组合是:先用 min/max 锁死大范围(比如“只能选未来30天”),再用 disabledDate 在这个范围内精细过滤(比如“其中只放行工作日”)。
注意两点:
min 和 max 必须是字符串格式(如 "2026-07-02"),传 new Date() 会带时分秒,导致当天下午之后的时间点意外被截断disabledDate 函数在 min/max 之外的日期上依然会被调用,但那些日期本就不可见——所以逻辑里不用额外判断是否超出范围,专注规则本身即可最常踩的坑是忘了最后的兜底 return false。比如这样写:
disabledDate: function(date) { if (!date) return false; if (date.getDay() === 0 || date.getDay() === 6) { return true; } // ❌ 缺少 else 或最终 return,其余日期也默认返回 undefined → laydate 当作 true 处理}
结果是除了周末,其他日期也全灰了。正确写法必须明确收尾:
return true
return false(不能漏,不能靠隐式返回)|| 连接条件,最后仍要 return false
这个 return false 看似简单,却是实际项目里 debug 半天才发现的问题根源。