简体   繁体   English

有2个日期,我需要根据第一个日期选择来阻止第二个日期的datepicker选项

[英]With 2 dates I need to block the datepicker option for 2nd date based on 1st date selection

I have two datepicker fromdate and todate. 我有两个datepicker fromdate和todate。 Based on fromdate selection, I need to block the dates above the fromdate in the second datepicker(toDate). 基于fromdate选择,我需要在第二个datepicker(toDate)中阻止fromdate以上的日期。

eg 例如

 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. 

How do I achieve this? 我该如何实现?

Assuming you're using jQuery UI's datepicker, I think you're looking for Date range. 假设您正在使用jQuery UI的datepicker,我想您正在寻找的是Date范围。 You'd have a markup like this : 您会有这样的标记:

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

Then, in the JS, 然后,在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 );
      }
    });
  });

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 日期选择器,第二个日期是从第一个日期起的X天 - Datepicker, 2nd date is X days from 1st date jQuery:根据第一个下拉菜单的选择更改第二个下拉菜单的选择 - jQuery: Change selection of 2nd dropdown based on selection of 1st 根据第一个选择设置第二个选择的选项 - Set option of the 2nd Select based on the 1st Select 每当我在第一个下拉菜单中更改选项时,都需要jquery将第二个下拉菜单的默认选项更改为“选择” - need jquery to change the default option of 2nd dropdown to “select” whenever i change options in 1st dropdown 如何限制第二个日期选择器不超过第一个日期选择器的选择日期? - How to restrict 2nd date picker no more than below the 1st date picker's selected date? 如何在第一个选择上禁用(或更改颜色)第二个下拉选项? - How to disable (or change color) of 2nd drop down option depenging on 1st selection? 根据对第一个下拉菜单的选择,将初始值加载到第二个下拉菜单中 - Load initial value into the 2nd dropdown based off of selection of the 1st dropdown 如何通过从关联数组中选择项目来基于第一下拉选择绑定第二下拉? - How to bind 2nd dropdown based on 1st dropdown selection by picking item from associative array? 根据 React.Js 中第一个下拉列表的选择填充第二个下拉列表 - Populate 2nd dropdown based on selection from 1st dropdown in React.Js 如何在第一天之前设置我的第二个日期选择器? - How do I set my 2nd datepicker one day ahead of the 1st?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM