在 jQuery UI 日期选择器上禁用一周中的特定日期 [英] Disable specific days of the week on jQuery UI datepicker

查看:33
本文介绍了在 jQuery UI 日期选择器上禁用一周中的特定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
可以使用 jQuery UI日期选择器是否可以禁用周六和周日(和节假日)?

我想在 jQuery UI 日期选择器上禁用某些日子,例如每个星期一或每个星期二或每个星期一、星期四、星期五等.

I would like to disable certain days like every monday or every tuesday or every monday, thursday friday, etc. on a jQuery UI datepicker.

我尝试使用 beforeShowDay,但这需要特定日期.我只想禁用一周中的一整天.

I tried to play with beforeShowDay, but that requires a specific date. I just want to disable an entire day of the week.

更新:感谢建议的解决方案,但它们都适用于特定日期.如果我想禁用全年的每个星期一和星期二怎么办.我该怎么做?

Update: Thanks for the suggested solutions, but they all work for specific dates. What if I wanted to disable every single Monday and Tuesday for the entire year. How would I do that?

推荐答案

您可以使用 <日期选择器的代码>beforeShowDate 选项 结合Date.getDay() 做你想做的事,像这样:

You can ue the beforeShowDate option of the datepicker combined with Date.getDay() to do what you want, like this:

​$("#datepicker").datepicker({
    beforeShowDay: function(date) {
        var day = date.getDay();
        return [(day != 1 && day != 2)];
    }
})​​​​​;​

你可以在这里看到一个工作演示,这只是获取日期,检查它是否是星期一(1) 或星期二 (2) 并在这种情况下为第一个数组条目返回 false.

You can see a working demo here, this just takes the date, checks if it's a Monday (1) or Tuesday (2) and returns false for the first array entry if that's the case.

这篇关于在 jQuery UI 日期选择器上禁用一周中的特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆