【问题标题】:jQuery Plugin - 1 month calendarjQuery 插件 - 1 个月的日历
【发布时间】:2012-08-31 10:22:25
【问题描述】:

我正在尝试确定一个 jQuery 插件,该插件将显示整月的日期长度方式(如下 - 数字反映一个月中的天数(仅限工作日)。

-3 4 5 6 7- -10 11 12 13 14- -17 18 19 20 21- -24 25 26 27 28-

从理论上讲,这种方法使当月的某一天成为列 - 然后可以将几个人的日历显示为下面的行。如下所示:

---------3 4 5 6 7- -10 11 12 13 14- -17 18 19 20 21- -24 25 26 27 28-
Person A X - - - -   -  -  -  X  -    -  -  -  X  X    -  -  -  -  -
Person B X X X - -   -  X  -  X  -    -  -  X  X  X    X  X  X  -  -

我的问题是“我怎样才能用 jQuery 实现上述目标?(我曾向 Google 查询以试图找到一个合适的插件 - 但我一直无法找到一个)”。

【问题讨论】:

  • 不能自己开发吗?
  • 这些数据是从哪里来的,你在哪里需要 jQuery?
  • 我可以自己开发它——没有底层数据结构——而且我不一定必须使用 jQuery。这只是我以前使用的一个框架。
  • 这个日历必须是可编辑的吗?

标签: jquery date jquery-plugins calendar


【解决方案1】:

好吧,lets get you started

(function($){
    var getWeekDaysInCurrentMonth = function(){
        // this will operate off of the current month
        // you can make the month an argument
        // and then d.setMonth(m)

        var d = new Date(), 
            daysInMonth = [], 
            currentDay;

        // go to first day of month
        d.setDate(1);
        var firstDay = d.getDate();
        // go to last day of month
        d.setDate(0);
        var lastDay = d.getDate();

        for (var i = firstDay; i <= lastDay; i++){
            d.setDate(i);
            // get the current day of the week in loop
            currentDay = d.getDay();
            // check not sunday or saturday
            if(currentDay !== 0 && currentDay !== 6)
                daysInMonth.push(i);                
        }
        return daysInMonth;
    };

    console.log(getWeekDaysInCurrentMonth());
    // OUTPUT: [1, 2, 3, 6, 7, 8, 9, 10, 13, 
    //            14, 15, 16, 17, 20, 21, 22, 23, 24, 27, 28, 29, 30, 31] 

})(jQuery)​;​

您的下一步是将此函数应用到一个 jQuery 插件中以输出一些表格标记。然后,您将向您的插件添加配置,以更改标记的显示方式、首先显示的月份等。如果您仔细阅读我的其他一些 jQuery 答案,您可以找到创建 jQuery 插件(或 google)的示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-27
    • 1970-01-01
    • 1970-01-01
    • 2012-01-25
    相关资源
    最近更新 更多