2016-06-24 33 views
0

私はjQuery-UI datepickerを使用しているサイトを開発していますが、問題はすべての日付を選択して、ユーザーが開始日と終了日を選択したときに配列に配置する必要があります。 jquery UI datepickerを使用しています:a ainglejQuery-UIで日付範囲を選択Datepicker

私はjQuery-UIのドキュメントをチェックしましたが、私の問題を解決するものは何も見つかりませんでした。

日付範囲をこのように選択します。

enter image description here

私はのjQuery-UIを使用する必要があり、そのいずれかの有用なアイデアは、あなたがこの方法を使用することができ、

おかげ

答えて

1

このようにdatepickerを作成しましたので、これ以上の回答は必要ありません。 おかげでここ

Fiddle

enter image description here

を働いています
1

を理解されるであろう。

1.ユーザーを2つの日付をクリックします

2. 2つの変数として保存します(startDate、endDate)

3.youループます

var numberOfDaysToAdd=0 
var startDate; 
var endDate; 
var dateCheck=startDate; 
var DatetoAddInArray = startDate; 
var array = []; 
while(DatetoAddInArray!=endDate){ 
    //every time you check if the date is equal to the endDate 
    //if is not you add it in the array with the dates and then 
    //you increase the index. 
    //the while loop ends when you find the end Date 
    //You can change your code to add or not the start and the end dates 
    numberOfDaysToAdd++; 
    DatetoAddInArray.setDate(DatetoAddInArray.getDate()+numberOfDaysToAdd); 
    array[numberOfDaysToAdd-1]=DatetoAddInArray; 
} 

上記は、終了日に開始されてからのすべての日付を格納するための簡単な方法である可能性があります。

(!)datePickerを使用してstartDateをクリックし、startDateの前にあるendDateをクリックできる場合は、正しい範囲を選択するようにユーザーに警告する必要があります。

ありがとうございました。

関連する問題