开发者

Highlighting dates between two selected dates jQuery UI Datepicker

开发者 https://www.devze.com 2022-12-26 21:00 出处:网络
I have one datepicker with numberOfMonths set to 2. Arrival Date and Departure Date are determined using this logic (within onSelect):
  • I have one datepicker with numberOfMonths set to 2.
  • Arrival Date and Departure Date are determined using this logic (within onSelect):

if ((count % 2)==0) {
      depart = $("#datepicker-1").datepicker('getDate');
      if (arriv > depart) { temp=arriv; arriv=depart; depart=temp; }
      $("#check-in").val($.datepicker.formatDate("DD, MM d, yy",arriv)); 
      $("#check-out").val($.datepicker.formatDate("DD, MM d, yy",depart));
     } else {
      arriv = $("#datepicker-1").datepicker('getDate');
      depart = null;
      if ((arriv > depart)&&(depart!=null)) { temp=arriv; arriv=depart; depart=temp; }
      $("#day-count").val('');
      $("#check-in").val($.datepicker.formatDate("DD, MM d, yy",arriv));
      $("#check-out").val($.datepicker.formatDate("DD, MM d, yy",depart));
     }

     if(depart!=null) { 
      diffDays = Math.abs((arriv.ge开发者_StackOverflowtTime() - depart.getTime())/(oneDay)); 
      if (diffDays == 0) { $("#day-count").val((diffDays+1)+' Night/s'); } else { $("#day-count").val(diffDays+' Night/s'); }
     }
  • Getting the number of days within these 2 dates has no problem
  • What I want now is highlight those dates starting from the Arrival to Departure
  • I tried working around the onSelect but had no luck.
  • I am now using beforeShowDay to highlight these dates but I can't seem to figure it out
  • Got a sample from here
  • Basically, it is customized to highlight 11 or 12 days after the selected date (Here's the code from that link).

    $('#datePicker').datepicker({beforeShowDay: function(date) {
                        if (selected != null && date.getTime() > selected.getTime() &&
                            (date.getTime() - selected.getTime()) 
  • Since I am new to using the UI, and the logic is not clear to me yet, I can't seem to figure this out. Any ideas on how I can make this highlight dates between the Arrival and Departure using my aforementioned logic used in determining the two?


Super old question but I came across the answer for anyone that finds this: http://jsfiddle.net/kVsbq/4/

JS

$(".datepicker").datepicker({
minDate: 0,
numberOfMonths: [12, 1],
beforeShowDay: function (date) {
    var date1 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input1").val());
    var date2 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input2").val());
    return [true, date1 && ((date.getTime() == date1.getTime()) || (date2 && date >= date1 && date <= date2)) ? "dp-highlight" : ""];
},
onSelect: function (dateText, inst) {
    var date1 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input1").val());
    var date2 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input2").val());
    if (!date1 || date2) {
        $("#input1").val(dateText);
        $("#input2").val("");
        $(this).datepicker();
    } else {
        $("#input2").val(dateText);
        $(this).datepicker();
    }
}
});


IF this helps.. :-)

$(function() {
     var togo=['10/25/2013']
     var datesArray=['10/27/2013','10/28/2013']
     var datesArray1=['10/25/2013','10/26/2013']
     var datesArray2=['10/24/2013']


        $( "#datepicker" ).datepicker({
            numberOfMonths: 2,

            selectMultiple:true,
            beforeShowDay: function (date) {
                var theday = (date.getMonth()+1) +'/'+ 
                            date.getDate()+ '/' + 
                            date.getFullYear();
                    return [true,$.inArray(theday, datesArray2) >=0?"specialDate":($.inArray(theday, datesArray)>=0?"specialDate2":($.inArray(theday, datesArray1)>=0?"specialDate1":''))];
                },

            onSelect: function(date){

             console.log("clicked"+date);  
            return [true,$.inArray(['10/24/2013'], togo) >=0?"specialDate":($.inArray(date, datesArray1)>=0?"specialDate1":'')] ;  

            }

        });
        //$.inArray(theday, datesArray) >=0?"specialDate":'specialDate1'
    });

http://jsfiddle.net/pratik24/Kyt2w/3/


Not quite an answer, but this may be useful:

http://www.eyecon.ro/datepicker/

Rather unfortunately named, but it seems like it could be what you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消