0

我有两个 datepicker fromdate 和 todate。根据 fromdate 选择,我需要在第二个 datepicker(toDate) 中阻止 fromdate 以上的日期。

例如

 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. 

我如何实现这一目标?

4

1 回答 1

1

假设您使用的是 jQuery UI 的日期选择器,我认为您正在寻找日期范围。你会有这样的标记:

<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

于 2013-07-16T17:35:52.417 回答