星期六只在.JS Datepicker中 [英] Saturdays only in .JS Datepicker

查看:162
本文介绍了星期六只在.JS Datepicker中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个预先集成的.js datepicker,并且需要确保只有星期六可以选择。

I'm working with a pre-integrated .js datepicker and need to ensure only Saturdays are selectable.

我的代码是当前的形式:

My code in it's current form:

(function($){
    "use strict";

$.fn.gdlr_datepicker_range = function(){
    $(this).datepicker({
        minDate: 0,
        dateFormat : 'yy-mm-dd',
        numberOfMonths: [1, 2],
        beforeShowDay: function(date) {



            var date1 = $.datepicker.parseDate('yy-mm-dd', $("#gdlr-check-in").val());
            var date2 = $.datepicker.parseDate('yy-mm-dd', $("#gdlr-check-out").val());
                        return [date.getDay() === 6, date1 && ((date.getTime() == date1.getTime()) || (date2 && date >= date1 && date <= date2)) ? "dp-highlight" : ""];


        },
        onSelect: function(dateText, inst) {
            var date1 = $.datepicker.parseDate('yy-mm-dd', $("#gdlr-check-in").val());
            var date2 = $.datepicker.parseDate('yy-mm-dd', $("#gdlr-check-out").val());
            if (!date1 || date2) {
                $("#gdlr-check-in").val(dateText);
                $("#gdlr-check-out").val("");
            } else {
                $("#gdlr-check-out").val(dateText).trigger('change');
            }
        },
        closeText: objectL10n.closeText,
        currentText: objectL10n.currentText,
        monthNames: objectL10n.monthNames,
        monthNamesShort: objectL10n.monthNamesShort,
        dayNames: objectL10n.dayNames,
        dayNamesShort: objectL10n.dayNamesShort,
        dayNamesMin: objectL10n.dayNamesMin,
        firstDay: objectL10n.firstDay
    });

如果有人可以用一个代码段指向正确的方向,我将非常感谢! p>

If somebody could point me in the right direction with a snippet, I would be extremely grateful!

推荐答案

引用 beforeShowDay param:


将日期作为参数,并且必须返回一个数组:

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


很容易猜出解决方案:只需更改 beforeShowDay 函数,以便在设置返回数组的第一个元素时检查选定日期的星期几:

It's easy to guess the solution: just change beforeShowDay function so that it checks the day of week of selected date when setting the first element of the returned array:

return [date.getDay() === 6, /* the rest remains the same */];

演示

这篇关于星期六只在.JS Datepicker中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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