jQuery PickMeUp datepicker:禁用日期数组 [英] jQuery PickMeUp datepicker: disable array of dates

查看:132
本文介绍了jQuery PickMeUp datepicker:禁用日期数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个名为 PickMeUp 的jQuery datepicker插件。

I'm using a jQuery datepicker plugin called PickMeUp.

我有日期标记工作,但无法解决如何禁用其中的日期。我的计划是在datepicker日历中禁用日期数组。

I have the datepicker working but can't work out how to disable dates in it. My plan is to have an array of dates that would be disabled on the datepicker calendar.

我设法使用以前版本的插件的文档( http://www.eyecon.ro/datepicker/ ),但我不知道如何添加一个日期数组。

I did manage to disable one date using the documentation from a previous version of the plugin, (http://www.eyecon.ro/datepicker/), but I can't figure out how to add an array of dates to it.

    $(document).ready(function(){   
        var now2 = new Date();
        now2.addDays(-1);
        now2.setHours(0,0,0,0);
        $('input#cdate').pickmeup({
        position  : 'right',                                        
            mode      : 'range',                        
            render: function(date) {
                return {
                    disabled: date.valueOf() == now2.valueOf()                          
                }
            }                           
        }); 
    }); 






更新



以下是工作代码。 (非常感谢 Niloct

    $(document).ready(function(){   
        var arDates = [new Date("2014-02-14").valueOf(),new Date("2014-02-11").valueOf(),new Date("2014-02-09").valueOf()];
        $('input#cdate').pickmeup({
        position  : 'right',                                        
            mode      : 'range',                        
            render: function(date) {
                return {
                    disabled: arDates.indexOf(date.valueOf()) != -1                         
                }
            }                           
        }); 
    }); 


推荐答案

好的,写下来:

valueOf() Date 对象,获取日期中的毫秒数(自01/01/1970以来)。

valueOf() is one of the methods of Date object that gets the number of milliseconds in a date (since 01/01/1970).

indexOf() Array 对象,用于检查元素是否是数组的成员。

indexOf() is a method of the Array object that checks if an element is a member of an array.

所以你的第一个代码是现在,你也得到了调整:

So your first code is spot on, also you got the tweaks:

var arDates = [new Date("2014-02-14").valueOf(),new Date("2014-02-11").valueOf(),new Date("2014-02-09").valueOf()];

disabled: arDates.indexOf(date.valueOf()) != -1

可能面对的是时区的问题。例如: new Date(2014-02-17)对于我来说,在2月17日并没有创建日期。由于我的时区,它下降了3个小时。

What you may face is issues with timezones. For instance: new Date("2014-02-17") for me does not create a date in Feb 17th. It falls back 3 hours due to my timezone.

这篇关于jQuery PickMeUp datepicker:禁用日期数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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