Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Jquery datepicker beforeShowDay浏览器不一致和更新问题_Php_Jquery_Jquery Ui_Datepicker - Fatal编程技术网

Php Jquery datepicker beforeShowDay浏览器不一致和更新问题

Php Jquery datepicker beforeShowDay浏览器不一致和更新问题,php,jquery,jquery-ui,datepicker,Php,Jquery,Jquery Ui,Datepicker,我在jQueryUIDatePicker中遇到了一点问题,我试图突出显示由ajax调用确定的给定月份的空闲天数 问题有两个方面: beforeShowDay似乎只在Chrome中正确执行,而不是FF或IE,FreeDay类根本没有添加到这些浏览器中 即使在Chrome中,当滚动到上一个月时,自由日类也不会添加,直到返回到该月,换句话说,自由日不会在该月的第一个视图中突出显示。不过,这似乎并不是一个将持续一个月的问题 javascript // declare freeDays global va

我在jQueryUIDatePicker中遇到了一点问题,我试图突出显示由ajax调用确定的给定月份的空闲天数

问题有两个方面:

  • beforeShowDay似乎只在Chrome中正确执行,而不是FF或IE,FreeDay类根本没有添加到这些浏览器中

  • 即使在Chrome中,当滚动到上一个月时,自由日类也不会添加,直到返回到该月,换句话说,自由日不会在该月的第一个视图中突出显示。不过,这似乎并不是一个将持续一个月的问题

  • javascript

    // declare freeDays global
    var freeDays = [];
    
    // perform initial json request for free days
    fetchFreeDays();
    
    $(document).ready(function()
    {
    
        // fairly standard configuration, importantly containing beforeShowDay and onChangeMonthYear custom methods
        $("#datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            showOtherMonths: true,
            selectOtherMonths: true,
            dateFormat: 'DD, d MM, yy',
            altField: '#date_due',
            altFormat: 'yy-mm-dd',
            beforeShowDay: highlightDays,
            onChangeMonthYear: fetchFreeDays,
            firstDay: 1 // rows starts on Monday
        });
    });
    
    // query for free days in datepicker
    function fetchFreeDays(year, month)
    {
        var start_date = '';
    
        // if a month and year were supplied, build a start_date in yyyy-mm-dd format
        if (year != undefined && month != undefined) {
          start_date = year +'-';
          start_date += month +'-';
          start_date += '01';
        }
    
        $.getJSON("ajax.todos.php?start_date="+ start_date, function(data){
             $.each(data, function(index, value) {
                freeDays.push(value.freeDate); // add this date to the freeDays array
            });
        });
    }
    
    // runs for every day displayed in datepicker, adds class and tooltip if matched to days in freeDays array
    function highlightDays(date)
    {
        for (var i = 0; i < freeDays.length; i++) {
          if (new Date(freeDays[i]).toString() == date.toString()) {
             return [true, 'free-day', 'no to-do items due']; // [0] = true | false if this day is selectable, [1] = class to add, [2] = tooltip to display
          }
        }
    
        return [true, ''];
    }
    
    css


    几个月前我写了一篇关于这方面的教程,可能会有一些额外的信息,这是

    问题在于
    fetchFreeDays()
    是异步的,因此可能
    $(“#datepicker”).datepicker()
    在填充
    freeDays
    数组之前就完成了执行,因此当页面第一次呈现时,您看不到任何内容


    尝试将
    $(“#datepicker”).datepicker()
    放在
    $.getJSON
    的回调函数中。

    仍然不太清楚。。。我在getJSON上实现回调时遇到了问题。现在,我已经尝试使用async:false选项切换到$.ajax,这似乎解决了在空闲日数组填充前几个月切换的问题,但我仍然无法在FF或IE中使用beforeShowDays。我已经将$('#datepicker').datepicker()放入在firebug中,我可以看到请求和响应看起来都很好,所以问题似乎出在highlightDays上。有没有任何原因可以解释为什么不同浏览器对toString行的处理方式不同?
    // ajax.todos.php
    $i = 0; // counter prevents infinite loop
    $cutoff = '61'; // limit on timespan (in days)
    $result = array();
    
    // if date is provided, use it, otherwise default to today
    $start_date = (!empty($start_date)) ? mysql_real_escape_string($start_date) : date('Y-m-d');
    $check_date = $start_date;
    $end_date = date('Y-m-d', strtotime("$start_date +$cutoff days")); // never retrieve more than 2 months
    
    while ($check_date != $end_date)
    {
        // check if any incomplete todos exist on this date
        if (mysql_result(mysql_query("SELECT COUNT(id) FROM " . DB_TODOS . " WHERE date_due = '$check_date'"), 0) == 0)
        {
            $result[] = array('freeDate' => $check_date);
        }
    
        // +1 day to the check date
        $check_date = date('Y-m-d', strtotime("$check_date +1 day"));
    
        // break from loop if its looking like an infinite loop
        $i++;
        if ($i > $cutoff) break;
    }
    
    header('Content-type: application/json');
    echo json_encode($result);
    
    /* override free days background in jquery ui datepicker */
    .free-day {
      background: #2e9500;
    }
    
    .free-day a {
      opacity: 0.7;
    }