2013-07-16 68 views
0

我有兩個datepicker fromdate和todate。根據fromdate選擇,我需要阻止第二個datepicker(toDate)中的fromdate之上的日期。有了2個日期,我需要根據第一次選擇日期來阻止第二個日期的日期選擇器

e.g

fromdate: 17/6/2013 (MM/DD/YYYY) 
todate: selection should be available from 17/6/2013. any date above 17/6/2013 should be disabled. 

如何實現這一目標?

+0

可能重複(HTTP://計算器.COM /問題/ 16368534/jQuery的日期選擇器,設置MINDATE) – adeneo

回答

1

假設你使用jQuery UI的datepicker,我認爲你正在尋找日期範圍。你有這樣的標記:

<label for="from">From</label> 
<input type="text" id="from" name="from" /> 
<label for="to">to</label> 
<input type="text" id="to" name="to" /> 

然後,在JS,

$(function() { 
    $("#from").datepicker({ 
     //not needed 
     defaultDate: "+1w", 
     //to show the month dropdown 
     changeMonth: true, 
     //the number of months to be shown when input is focussed 
     numberOfMonths: 1, 
     //**Important!** 
     onClose: function(selectedDate) { 
     //dynamically set min-date of second datepicker to selected date in the first datepicker 
     $("#to").datepicker("option", "minDate", selectedDate); 
     } 
    }); 
    $("#to").datepicker({ 
     defaultDate: "+1w", 
     changeMonth: true, 
     numberOfMonths: 1, 
     onClose: function(selectedDate) { 
     //dynamically set max-date property of #from text box 
     $("#from").datepicker("option", "maxDate", selectedDate); 
     } 
    }); 
    }); 

文檔:http://jqueryui.com/datepicker/#date-range

[jQuery的日期選擇器設置MINDATE]的
相關問題