JQuery Datepicker多选和突出显示日期

时间:2014-02-10 14:29:59

标签: jquery highlight multipleselection datapicker

我正在尝试将Datapicker用作日历,并希望突出显示特殊日期,但也希望使用多日期选择。 多项选择正在运作,而且highligt日期也在运作。 但是,如果我尝试在同一个日历中使用它们,它就不会工作。 我希望你能理解我,因为英语不是我的母语。

jQuery("#kalender-container").datepicker
({
    showButtonPanel: false,
    selectMultiple:true,
    firstDay: 1, 
    showWeek: true,
    beforeShowDay: function (date) 
        {
            var theday = (date.getMonth()+1) +'/'+ 
            date.getDate()+ '/' + 
            date.getFullYear();
            return [true,$.inArray(theday, datesArray) >=0?"specialDate":($.inArray(theday, datesArray1)>=0?"specialDate1":'')];
        }
});

我希望soneone可以帮助我解决问题。

非常感谢您的回答。

编辑selectMultiple

的代码
<script>
var dates = new Array();
function addDate(date) {if (jQuery.inArray(date, dates) < 0) dates.push(date);}
function removeDate(index) {dates.splice(index, 1);}

// Adds a date if we don't have it yet, else remove it
function addOrRemoveDate(date)
{
  var index = jQuery.inArray(date, dates); 
  if (index >= 0)
    removeDate(index);
  else 
    addDate(date);
}

// Takes a 1-digit number and inserts a zero before it
function padNumber(number)
{
  var ret = new String(number);
  if (ret.length == 1)
    ret = "0" + ret;
  return ret;
}

jQuery(function() {
      $.datepicker.regional['de'] = {
                monthNames: ['Januar','Februar','März','April','Mai','Juni',
                'Juli','August','September','Oktober','November','Dezember'],
                monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun',
                'Jul','Aug','Sep','Okt','Nov','Dez'],
                weekHeader: 'Wo', weekStatus: 'Woche des Monats',
                dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
                dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
                dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
                 firstDay: 1,showWeek:true};
        $.datepicker.setDefaults($.datepicker.regional['de']);
jQuery("#kalender-container").datepicker({onSelect: function(dateText, inst) { addOrRemoveDate(dateText); },
                              beforeShowDay: function (date){
                                var year = date.getFullYear();
                                // months and days are inserted into the array in the form, e.g "01/01/2009", but here the format is "1/1/2009"
                                var month = padNumber(date.getMonth() + 1);
                                var day = padNumber(date.getDate());
                                // This depends on the datepicker's date format
                                var dateString = month + "/" + day + "/" + year;

                                var gotDate = jQuery.inArray(dateString, dates);
                                if (gotDate >= 0) {
                                  // Enable date so it can be deselected. Set style to be highlighted
                                  return [true,"ui-state-highlight"]; 
                                }
                                // Dates not in the array are left enabled, but with no extra style
                                return [true, ""];
                              }
                        });
});

</script>

0 个答案:

没有答案