2012-05-21 47 views
1

我有兩個輸入字段包含觸發日期選擇器打開的類。兩個工作都很好獨立,即當我點擊其中一個或另一個時,但我希望兩個日期選擇器在任何一個輸入字段被點擊時打開。同時打開兩個jquery datepickers

下面是代碼

$(document).ready(function() { 

        $(".datefields").datepicker({ dateFormat: 'dd/mm/yy',numberOfMonths: 1, yearRange: "2012:2014", changeYear: true, changeMonth: true});   

的腳本的一部分,這是HTML

<div id="quoteformcollection"> 
<h1>Collection</h1> 

<input type"text" class="startTbl locationfields" id="AutoLocStart" value="Please Type a Collection Location"onclick="clearVal(this);"/> 
    <input type="hidden" id="DepotStart" value=""/></td> 

<input type="text" class="datefields" id="collectiondate" value="21/05/2012"/> 
<input type"text" class="timefields" value="12:00" /> 
</div> 

<div id="quoteformreturn"> 
<h1>Return</h1> 

<input type"text" class="locationfields" value="Enter the city or location for return" /> 
<input type"text" id="returndate" class="datefields" value="21/05/2012" /> 
<input type"text" class="timefields" value="12:00" /> 
</div> 

我試圖尋找一個答案自己,但很新的jQuery和掙扎一下,讓任何幫助將非常感激。

我還想要在第一個日期選擇器中選擇任何值,因爲第二個日期中的默認日期將增加x天,這再次我不確定最好的方式去實現它。

任何意見將非常感激!

回答

0

試試這個代碼,例如兩個datapickers鏈接:

$('#collectiondate').datepicker({ 
    dateFormat: "@", 
    onSelect: function(dateText, inst) { 
     var dateText = eval(dateText); 
     var min = new Date(); 
     min.setTime(dateText); 
     $('#end').datepicker('option', 'minDate', min); 
    } 
}); 

$('#returndate').datepicker({ 
    dateFormat: "@", 
});