2016-11-23 164 views
0

這被標記爲較早的重複,我沒有得到任何答案。這不是重複的,所以請不要將它標記爲,另一篇文章涉及到限制第二個日期到第一個選擇中的當前選定日期,我沒有試圖這樣做,已經有了。我正在嘗試將+3天添加到第二個日曆/日期。因此,如果我選擇今天的第一天和第二天的日期,我不應該從該日期+3天內選擇日期。在jQuery UI中將第二個日期限制爲+日期日期選擇器

:從日期爲21/12/2016然後在第二個字段我不能選擇然後24/12/2016較早的日期。

我在datepicker中遇到日期範圍問題。我需要在選定的「carrental_from_date」後至少3天有「carrental_to_date」,但似乎沒有任何工作。

我試圖對「TO_DATE」到「+ 3D」,但它並不似乎挑選了改變「的minDate」,我發現這個在這裏一個例子:http://jsfiddle.net/jquerybyexample/dxbtp/494/,但我沒能拿到工作。不知道我在這裏做錯了什麼,並希望你們中的一位天才能夠指引我朝着正確的方向前進。

jQuery('#carrental_from_date' + element_id).datepicker({ 
      //showOn: "both", 
      beforeShow: carrental_customRange, 
      dateFormat: "<?php echo date_format_js(isset($theme_options['date_format']) ? $theme_options['date_format'] : ''); ?>", 
      firstDay: "<?php echo (isset($theme_options['date_format_first_day']) ? (int) $theme_options['date_format_first_day'] : 0); ?>", 
      dayNamesMin: ["<?php echo CarRental::t('Su') ?>", "<?php echo CarRental::t('Mo') ?>", "<?php echo CarRental::t('Tu') ?>", "<?php echo CarRental::t('Wu') ?>", "<?php echo CarRental::t('Th') ?>", "<?php echo CarRental::t('Fr') ?>", "<?php echo CarRental::t('Sa') ?>"], 
      monthNames: ["<?php echo CarRental::t('January') ?>", "<?php echo CarRental::t('February') ?>", "<?php echo CarRental::t('March') ?>", "<?php echo CarRental::t('April') ?>", "<?php echo CarRental::t('May') ?>", "<?php echo CarRental::t('June') ?>", "<?php echo CarRental::t('July') ?>", "<?php echo CarRental::t('August') ?>", "<?php echo CarRental::t('September') ?>", "<?php echo CarRental::t('October') ?>", "<?php echo CarRental::t('November') ?>", "<?php echo CarRental::t('December') ?>"], 
      dayNames: ["<?php echo CarRental::t('Sunday') ?>", "<?php echo CarRental::t('Monday') ?>", "<?php echo CarRental::t('Tuesday') ?>", "<?php echo CarRental::t('Wednesday') ?>", "<?php echo CarRental::t('Thursday') ?>", "<?php echo CarRental::t('Friday') ?>", "<?php echo CarRental::t('Saturday') ?>"], 
      nextText: "<?php echo CarRental::t('Next') ?>", 
      prevText: "<?php echo CarRental::t('Prev') ?>", 
      minDate: 0, 
      onSelect: function() { 
       carrental_update_business_hours(element_id); 
      } 
     }); 

     jQuery('#carrental_to_date' + element_id).datepicker({ 
      //showOn: "both", 
      beforeShow: carrental_customRange, 
      dateFormat: "<?php echo date_format_js(isset($theme_options['date_format']) ? $theme_options['date_format'] : ''); ?>", 
      firstDay: "<?php echo (isset($theme_options['date_format_first_day']) ? (int) $theme_options['date_format_first_day'] : 0); ?>", 
      dayNamesMin: ["<?php echo CarRental::t('Su') ?>", "<?php echo CarRental::t('Mo') ?>", "<?php echo CarRental::t('Tu') ?>", "<?php echo CarRental::t('Wu') ?>", "<?php echo CarRental::t('Th') ?>", "<?php echo CarRental::t('Fr') ?>", "<?php echo CarRental::t('Sa') ?>"], 
      monthNames: ["<?php echo CarRental::t('January') ?>", "<?php echo CarRental::t('February') ?>", "<?php echo CarRental::t('March') ?>", "<?php echo CarRental::t('April') ?>", "<?php echo CarRental::t('May') ?>", "<?php echo CarRental::t('June') ?>", "<?php echo CarRental::t('July') ?>", "<?php echo CarRental::t('August') ?>", "<?php echo CarRental::t('September') ?>", "<?php echo CarRental::t('October') ?>", "<?php echo CarRental::t('November') ?>", "<?php echo CarRental::t('December') ?>"], 
      dayNames: ["<?php echo CarRental::t('Sunday') ?>", "<?php echo CarRental::t('Monday') ?>", "<?php echo CarRental::t('Tuesday') ?>", "<?php echo CarRental::t('Wednesday') ?>", "<?php echo CarRental::t('Thursday') ?>", "<?php echo CarRental::t('Friday') ?>", "<?php echo CarRental::t('Saturday') ?>"], 
      nextText: "<?php echo CarRental::t('Next') ?>", 
      prevText: "<?php echo CarRental::t('Prev') ?>", 
      minDate: 0, 
      onSelect: function() { 
       carrental_update_business_hours(element_id); 
      } 
     }); 

回答

1

從API爲minDate

最小可選日期。設置爲空時,沒有最小值。 支持多種類型:

日期:包含最小日期的日期對象。

號碼:從今天開始的幾天。例如2表示從今天開始的兩天,-1表示昨天。

字符串:一個由dateFormat選項或相對日期定義格式的字符串。相對日期必須包含價值和週期對;有效期間爲「y」多年,「m」數月,「w」數週,「d」數日。例如,「+ 1m + 7d」表示從今天起一個月零七天。

我會建議String方法:+3d。在「發件人」字段中選擇日期時,可以將該值設置爲「收件人」字段的日期。

工作例如從你的例子:http://jsfiddle.net/dxbtp/871/

jQuery的

$(document).ready(function() { 
    $("#txtFromDate").datepicker({ 
    onSelect: function(selected) { 
     $("#txtToDate").datepicker("setDate", selected); 
     $("#txtToDate").datepicker("option", "minDate", "+3d"); 
    } 
    }); 

    $("#txtToDate").datepicker({ 
    onSelect: function(selected) { 
     $("#txtFromDate").datepicker("setDate", selected); 
     $("#txtFromDate").datepicker("option", "maxDate", "-3d") 
    } 
    }); 
}); 
相關問題