0

我有两个日期选择器(Materializecss),一个用于签入日期,另一个用于签出日期。我想要的是我想要退房日期最小日期是入住日期前 1 天。我在pickadate js上得到了这个代码,但问题是在结束日期选择器中启用了第一个日期选择器上的选定日期。我想要发生的是当我选择 9/22/2017 时,结束日期选择器上的最小日期应该是 9/23/2017

$('#dp_ci').pickadate(
    {
        selectMonths: true, // Creates a dropdown to control month
        today: 'Today',
        clear: 'Clear',
        close: 'Ok',
        min: new Date()
      });


    var from_$input = $('#dp_ci').pickadate(),
    from_picker = from_$input.pickadate('picker')

    var to_$input = $('#dp_co').pickadate(),
    to_picker = to_$input.pickadate('picker')


    // Check if there’s a “from” or “to” date to start with.
    if ( from_picker.get('value') ) 
    {
      to_picker.set('min', from_picker.get('select'))
    }
    if ( to_picker.get('value') ) 
    {
      from_picker.set('max', to_picker.get('select'))


    }
    // When something is selected, update the “from” and “to” limits.
    from_picker.on('set', function(event) 
    {

      if ( event.select ) 
      {
        to_picker.set('min', from_picker.get('select'))    
      }

      else if ( 'clear' in event ) 
      {
        to_picker.set('min', false)
      }

    })

    to_picker.on('set', function(event) 
    {
      if ( event.select ) 
      {
        from_picker.set('max', to_picker.get('select'))
      }
      else if ( 'clear' in event ) 
      {
        from_picker.set('max', false)
      }
    })
4

1 回答 1

0
 $('#dp_ci').pickadate(
    {
        selectMonths: true, // Creates a dropdown to control month
        today: 'Today',
        clear: 'Clear',
        close: 'Ok',
        min: new Date()
      });




    var from_$input = $('#dp_ci').pickadate(),
    from_picker = from_$input.pickadate('picker')

    var to_$input = $('#dp_co').pickadate(),
    to_picker = to_$input.pickadate('picker')


    // Check if there’s a “from” or “to” date to start with.
    if ( from_picker.get('value') ) 

    {        
       var today = new Date($('#dp_ci').val());
       today.setDate(today.getDate() + 1)
      to_picker.set('min', today)
    }
    if ( to_picker.get('value') ) 
    {
       var today = new Date($('#dp_co').val());
    today.setDate(today.getDate() - 1)
      from_picker.set('max', today)


    }
    // When something is selected, update the “from” and “to” limits.
    from_picker.on('set', function(event) 
    {

      if ( event.select ) 
      {
         var today = new Date($('#dp_ci').val());
    today.setDate(today.getDate() + 1)
        to_picker.set('min', today)    
      }

      else if ( 'clear' in event ) 
      {

        to_picker.set('min', false)
      }

    })

    to_picker.on('set', function(event) 
    {
      if ( event.select ) 
      {
        var today = new Date($('#dp_co').val());
    today.setDate(today.getDate() - 1)
        from_picker.set('max', today)
      }
      else if ( 'clear' in event ) 
      {

        from_picker.set('max', false)
      }
    })

我添加了今天的变量(抱歉不能再更改名称了 :)

于 2017-09-18T06:56:11.703 回答