简体   繁体   中英

To disable dynamic dates and days in jquery datepicker

I have used jquery ui datepicker and i want to disable some specific date range coming from database and also days.so i have written below code but it's not working

function checkAvailability(mydate){
var $return=true;
var $returnclass ="available";
$checkdate = $.datepicker.formatDate('dd-mm-yy', mydate);
    var datas  =$.parseJSON(disabledDays);
            var unavailableDates=[];
            for(i in datas){
                unavailableDates.push(datas[i]); 
            }

 for(var i = 0; i < unavailableDates.length; i++) 
    {    
       if(unavailableDates[i] == $checkdate)
       {
            $return = false;
            $returnclass= "unavailable";
       }
    } 
 var day = mydate.getDay();         
 //return [(day!=0) && $return,$returnclass];

        var disabledDaysRange  =$.parseJSON(disabledDays_Range);
        var unavailableDays=[];
        for(j in disabledDaysRange){
                unavailableDays.push(disabledDaysRange[j]); 
         }
         var days_return = '';
        for(var j = 0; j < unavailableDays.length; j++) 
         {    
                if(unavailableDays[j] == day)
                    {
                        days_return =days_return.concat( day +'!= '+unavailableDays[j]+ ' && '); 
                    }
          } 
              if(days_return!=''){
                    days_return = "( " + days_return + ")"; 
                    days_return = days_return.replace("&& ) ", " )");
               }
           if(days_return!=''){         
            return [days_return && ($return),$returnclass];
           }else{
               return [$return,$returnclass];
           }
}     

TRy demo at http://jsfiddle.net/devmgs/E9m8G/

$(function() {
    $( "#datepicker" ).datepicker({
    minDate: 2,
    maxDate: "+3M",
    dateFormat: "DD, d MM, yy",
    beforeShowDay: function(day) {
        var newday = day.getDay();
        if (newday == 1 || newday == 2 || newday == 3 || newday == 4) {
            return [false, ""]
        }
        else {
            var disabledDays = ["10-25-2013"];        
        var m = day.getMonth(), d = day.getDate(), y = day.getFullYear();
for (i = 0; i < disabledDays.length; i++) {
    if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1) {
        return [false];
    }
}
return [true];
    }
        }


});
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM