duan2891 2011-07-07 06:54
浏览 108

在jQuery datepicker中的beforedayshow

how can i use beforeShowDay in jQuery datepicker to retrieve information from database by date order?

please, with a small code

  • 写回答

1条回答 默认 最新

  • drj14664 2011-07-13 19:13
    关注

    Best to order the events when selecting them from the database so they are already sorted. See if this helps...

    <style type="text/css">
    
    td.highlight, table.ui-datepicker-calendar tbody td.highlight a { 
        background: none !important;
        background-color: #fffac2 !important; 
        color: #FF0000;
    }
    
    </style>
    
    <script>
    $(document).ready(function(){
    
        // get the current date
        var today = new Date();
        var m = today.getMonth(), d = today.getDate(), y = today.getFullYear();
    
        var eventDates = [];
        fetchEventDays(y, m+1);     // Get User events for the current year and month.
    
        // ------------------------------------------------------------------
        // fetchEventDays - The ajax call below is synchronous (NOT asynchronous).
        // eventDates array must be populated prior to adding the beforeShowDay option
        // to the datepicker, otherwise, highlightDays() will have an empty eventDates array.
        // ------------------------------------------------------------------
        function fetchEventDays(year, month, inst) {
            var url ='<%config.db_cgi_url%>/eventmgr-ajax.cgi?do=get_event_dates&yr=' + year + '&mo=' + month;
            eventDates = [];    // reset to empty array
    
            $.ajax({
                url: url,
                async: false,
                success: function(result){
                    var event_dates = result.split(',');
                    for(var i = 0; i < event_dates.length; i++) {
                        var date_parts = event_dates[i].split('-');
                        eventDates.push(new Date(date_parts[0], date_parts[1]-1, date_parts[2]));
                    }                       
                }
            });
        }
    
        // ------------------------------------------------------------------
        // highlightDays - Add a custom css class to dates that exist in the
        // eventDates array. Must also add the css for td.highlight (above).
        // ------------------------------------------------------------------
        function highlightDays(date) {
            for (var i = 0; i < eventDates.length; i++) {
                if ((eventDates[i].getTime() == date.getTime())) {
                    var count = 0;
                    for(var ii = 0; ii < eventDates.length; ++ii){
                        if(date.getTime() == eventDates[ii].getTime())
                            count++;
                    }
                    var event_text = (count > 1) ? 'Events' : 'Event';
                    return [true, 'highlight', count + ' ' + event_text];
                }
            }
    
            // Return true to allow dates with or without an event to be selectable.
            // Return false to allow only dates WITH an event to be selectable.
            return [true, ''];
        }
    });
    
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角