jquery datepicker突出节日 [英] jquery datepicker highlight holidays

查看:105
本文介绍了jquery datepicker突出节日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个jquery datepicker日历,将突出显示假期,并将假日名称作为工具提示,当日期戳的日期被悬停时。假日日期来自php文件(holidays.php)。我的问题是...我似乎不能突出所有的假期,它只突出一个日期。更具体地说,只是第一个返回的日期。

I am trying to make a jquery datepicker calendar that would highlight holidays and make the holiday name as a tooltip when the day on the datepicker is hovered. The holiday dates came from a php file ( holidays.php ). My problem is..I can't seem to highlight ALL the holidays instead, it highlights just one date. More specifically, just the first returned date.

$(document).ready(function (){
  var holiDays = (function () {
    var val = null;
    $.ajax({
        'async': false,
        'global': false,
        'url': 'holidays.php',
        'success': function (data) {
        val = data;
        }
    });
    return val;
    })();

  var result = [];
  var holiDays = holiDays.split(',');

 var s, k;

    for (s = 0, k = -1; s < holiDays.length; s++) {
        if (s % 4 === 0) {
            k++;
            result[k] = [];
        }

        result[k].push(holiDays[s]);
    }

  // This for loop is to check whether the values stored in result[] are correct

  for (i = 0; i < result.length; i++) {
  var f=result[i][0]+"-"+result[i][1]+"-"+result[i][2];
  alert(f); 
  }


  function nationalDays(date) {
    var m = date.getMonth();
    var d = date.getDate();
    var y = date.getFullYear();

  for (i = 0; i < result.length; i++) {
  var f=result[i][0]+"-"+result[i][1]+"-"+result[i][2];
 // WHEN I ALERT THE VALUE OF f HERE, 
 // IT ALWAYS DISPLAY THE FIRST VALUE IN THE RESULT ARRAY. WHY?
 alert(f);

  var d = new Date(f);

                 if (date.getFullYear() == d.getFullYear()
                      && date.getMonth() == d.getMonth()
                      && date.getDate() == d.getDate()) {
                    return [true, 'holiday', result[i][3]];
                 } else {
                  return [true];
                 }
               } 

  }


  $(function() { 
        $('input.pickerClass').live('click', function() {
            $(this).datepicker({dateFormat: 'yy-mm-dd', beforeShowDay: nationalDays  }).focus();
        });

  });



});

当我提醒数组内的值 result [] nationalDays函数之外,存储的值似乎是正确的。

when I alert the values inside the array result[] outside of the nationalDays function, the values stored seemed to be correct.

  for (i = 0; i < result.length; i++) {
  var f=result[i][0]+"-"+result[i][1]+"-"+result[i][2];
  alert(f); 
  }

但由于某些原因,当我提醒 result [] 在countryDays函数下面的for循环中,它只返回存储在数组result []中的第一个日期。但为什么?

but for some reason, when I alert the values of the result[] INSIDE the for loop under the nationalDays function, it only returns the first date stored in the array result[]. But why?

任何人都有想法?我会非常感激。

Anyone has ideas?.. I would appreciate it so much. :)

推荐答案

我已经知道我错了什么。

I already know where I've gone wrong.

if (date.getFullYear() == d.getFullYear()
                      && date.getMonth() == d.getMonth()
                      && date.getDate() == d.getDate()) {
                    return [true, 'holiday', result[i][3]];
                 } else {
                  return [true];
                 }

应该是

if (date.getFullYear() == d.getFullYear()
                      && date.getMonth() == d.getMonth()
                      && date.getDate() == d.getDate()) {
                    return [true, 'holiday', result[i][3]];
                 } 
                  return [true];

我刚刚删除了else语句,它的工作!

I just removed the else statement and it worked!

这篇关于jquery datepicker突出节日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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