2011-01-22 41 views
0

目前,我有這樣的自定義函數:日期選擇器 - 使用默認的功能使用自定義功能

var $myBadDates = new Array(<?php foreach($aryDates as $disabledate) { echo ' "$disabledate",'; } echo " 1"; ?>); 
// Creates the array (The echo " 1"; is merely to close the array and will not affect the outcome 
function checkAvailability(mydate) { 
    var $return = true; 
    var $returnclass = "available"; 
    $checkdate = $.datepicker.formatDate('yy-mm-dd', mydate); 
    for (var i = 0; i < $myBadDates.length; i++) { 
     if ($myBadDates[i] == $checkdate) { 
      $return = false; 
      $returnclass = "unavailable"; 
     } 
    } 
    return [$return, $returnclass]; 
} 

的日期選擇器部分都按這樣的:

$(function() { 
    //To enable End Date picker only when Start Date has been chosen (And to disable all dates prior of said date) 
    var end = $('#enddate').datepicker({ 
     numberOfMonths: 3, 
     stepMonths: 3, 
     beforeShowDay: checkAvailability 
    }); 
    // Defining a function, because we're binding this to two different events 
    function enableEnd() { 
     end.attr('disabled', !this.value.length) // Enable the end input element if the first one has anything in it 
     .datepicker('option', 'minDate', this.value); // Set the minimum date to the date in the first input 
    } 
    //End of function 
    // Datepicker 
    $('#startdate').datepicker({ 
     numberOfMonths: 3, 
     stepMonths: 3, 
     beforeShowDay: checkAvailability, 
     minDate: +1, 
     onSelect: enableEnd // Call enableEnd when a date is selected in the first datepicker 
    }).bind('input', enableEnd); // Do the same when something is inputted by the user 
    //hover states on the static widgets 
    $('#dialog_link, ul#icons li').hover(

    function() { 
     $(this).toggleClass('ui-state-hover'); 
    }); 
}); 
//End of Function​ 

我做的是從我的SQL DB中,我使用了一個自定義函數,將開始日期和結束日期更改爲日期數組,然後將它們推入單個數組中,並用于禁用所述日期。
第二個日期選擇器僅在來自第一個日期選擇器的有效日期返回爲TRUE時啓用。

現在的問題是這樣的:
我可以封鎖所有日期,我必須。大。但現在,我怎樣才能在這個週末屏蔽週末呢?
beforeShowDay: $.datepicker.noWeekends無法工作,因爲我已經在使用自定義函數。所以,我必須進一步定製我的自定義功能。我不能使用getDate()並顯示> 0和< 7,那麼我該如何解決這個問題?

任何幫助,甚至小費的答案都會有所幫助。我一直在嘗試這一點,而且我沒有到任何地方。謝謝。

+0

'GETDATE()'將無法工作。即使創建一個重複相同過程的函數也是行不通的。 – 2011-01-26 10:36:26

回答

1

似乎很簡單,但我不明白爲什麼你不能使用getDay()功能:

function checkAvailability(d) { 
    if (
     d.getDay() == 6 /* saturday */ || 
     d.getDay() == 0 /* sunday */ 
    ) { 
     return [false,'unavailable unavailable-cuz-its-weekend']; 
    } 
    $checkdate = $.datepicker.formatDate('yy-mm-dd', d); 
    for (var i = 0; i < $myBadDates.length; i++) { 
     if($myBadDates[i] == $checkdate) 
     { 
      return [false, "unavailable"]; 
     } 
    } 
    return [true, "available"]; 
} 
+0

正如我所說,它不會工作。 – 2011-01-29 05:22:37