2012-10-25 74 views
0

我有6個不同的輸入字段。他們每個人都成對分組。將日期範圍的jQuery datepicker放置到各種輸入

在這裏,他們是:

<input name="fecha-in" type="text" id="from" size="40" height="25" class="date" /> 
<input name="fecha-fin" type="text" id="to" size="40" height="25" class="date" /> 
<input name="tfecha-in" type="text" id="from1" size="40" height="25" class="date" /> 
<input name="tfecha-fin" type="text" id="to1" size="40" height="25" class="date" /> 
<input name="bfecha-in" type="text" id="from2" size="40" height="25" class="date" /> 
<input name="bfecha-fin" type="text" id="to2" size="40" height="25" class="date" /> 

而且這六個我需要與日期範圍內添加了jQuery日期選擇器。我可以讓它在一對上工作,但我不知道如何將這個相同的代碼添加到所有3對。任何幫助將不勝感激。

這裏是我的jQuery:

$(function() { 
    $("#from").datepicker({ 
     defaultDate: "+1w", 
     changeMonth: true, 
     numberOfMonths: 3, 
     onClose: function(selectedDate) { 
      $("#to").datepicker("option", "minDate", selectedDate); 
     } 
    }); 

    $("#to").datepicker({ 
     defaultDate: "+1w", 
     changeMonth: true, 
     numberOfMonths: 3, 
     onClose: function(selectedDate) { 
      $("#from").datepicker("option", "maxDate", selectedDate); 
     } 
    }); 
}); 

謝謝你的人誰可以點我在正確的方向!

回答

1

這裏的現場演示: http://jsfiddle.net/MMMQn/1/

基礎上你的HTML,我遍歷輸入,帶類date

jQuery(".date").each(function(index, value) { 
    ...  
} 

然後我決定哪一對是現在(對於第一個有沒有額外的ID標識符,其餘的它上升):

var inputId = (index === 0) ? "" : index.toString(); 

最後,我添加了這個inputId字符串到jQuery選擇器並綁定您提供的代碼。

+0

這工作就像一個奇蹟..非常感謝你花時間來幫助! – liveandream

+0

很高興我能幫忙:) – kamil

相關問題