jquery datepicker 设置只显示周一和周末

<script type="text/javascript">
    $(document).ready(function(){

        $("#start_week").datepicker({
            beforeShowDay: nonWorkingDates,
            numberOfMonths: 1,
            firstDay: 1
        });

        function nonWorkingDates(date){
            var day = date.getDay(), Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6;
            var closedDays = [[Saturday], [Tuesday],[Wednesday],[Thursday],[Friday]];
            for (var i = 0; i < closedDays.length; i++) {
                if (day == closedDays[i][0]) {
                    return [false,'CLOSED'];
                }
            }
            return [true,''];
        }


    });
</script>

“CLOSED”貌似是Datepicker内置的一个什么值,设置为”CLOSED”则当天的日期是不可选的。

ui.Datepicker.js里关于beforeShowDay的一些注释:

beforeShowDay: null, // Function that takes a date and returns an array with
// [0] = true if selectable, false if not, [1] = custom CSS class name(s) or '',
// [2] = cell title (optional), e.g. $.datepicker.noWeekends


A function that takes a date as a parameter and must return an array with:

[0]: true/false indicating whether or not this date is selectable
[1]: a CSS class name to add to the date's cell or "" for the default presentation
[2]: an optional popup tooltip for this date

第三个参数可以在该日期上显示title,提示节假日名称。(比如国庆)

return [false, 'customCss','国庆'];  

参考:http://www.itstrike.cn/Question/51bf073c-ef71-43cb-a6ce-e09ec3bc24da.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值