简体   繁体   English

在日期选择器上禁用给定日期的过去日期

[英]disable past dates from given date on datepicker

I am trying to have a date Range selected using the UI date picker.我正在尝试使用 UI 日期选择器选择一个日期范围。

in the from field people should not be able to view or select dates previous to the given day.在来自现场的人不应该能够查看或 select 日期之前给定的一天。

My Code:我的代码:

<input type="text" class="form-control" name="from_date" id="f_date"
                       value="{{ Session::get('reviewerJoiningInfo.join_date') ? Session::get('reviewerJoiningInfo.join_date') : null }}"
                       placeholder="From Date" onkeydown="return false" autocomplete="off">

getting a date from the session从 session 获取日期

$('#f_date').datepicker({
                format: 'dd-mm-yyyy',
            }).on('changeDate', function (ev) {
                    var rev_join_date = $('#f_date').val()
                    var reviewer_join_date = $('#reviewer_join_date').val()
                    if(rev_join_date < reviewer_join_date){
                        $('#f_date').val(reviewer_join_date)
                    }
                    $(this).datepicker('hide');
                }
            );

I used minDate: date but not working.我使用minDate: date但没有工作。

To disable past year date you can pass yearrange in parameters.要禁用过去一年的日期,您可以在参数中传递 yearrange。 like喜欢

yearRange: '1950:2013', // specifying a hard coded year range

or或者

   yearRange: "c-100:c+0", // last hundred years and current years

Example:例子:

$(document).ready(function() {
    $("#date").datepicker({
        changeYear:true,
        yearRange: "2005:2015"
    });
});

previous 10 years and next 10 years:过去10年和未来10年:

 $('#datepicker2').datepicker({
     changeMonth: true,
     changeYear: true,
     minDate: 0,
     yearRange: 'c-10:c+20',

 }); 

if you want to disable past Date you can pass startDate or minDate如果你想禁用过去的日期,你可以传递 startDate 或 minDate

  $('#date').datepicker({
    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
     minDate: new Date(),
});

FIDDLE: For disabling past dates https://jsfiddle.net/p0deLk56/ FIDDLE:用于禁用过去的日期https://jsfiddle.net/p0deLk56/

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

相关问题 Bootstrap Datepicker在设置第一个日期字段后禁用过去日期 - Bootstrap Datepicker Disable Past Dates After First Date Field is Set 在 JQuery 日期选择器中禁用除一个特定日期之外的所有过去日期 - To disable all past dates except one particular date in JQuery datepicker 在Datepicker JS中禁用过去的日期 - Disable past dates in datepicker js 敲除js以从引导日期选择器中的选定日期禁用过去的日期 - Knockout js to disable past date from the selected date in bootstrap datepicker 使用“ Stefan Petre”的DatePicker禁用过去的日期 - Disable Past Dates using DatePicker by 'Stefan Petre' 通过从另一个日期选择器中选择日期来禁用JQuery日期选择器日期 - Disable JQuery datepicker dates by picking a date from another datepicker 如何在日历控件中从今天的日期禁用过去的日期? - How to disable past dates from today's date in calendar controle? 如何使用 Material ui reactjs 从今天开始禁用过去的日期? - How to disable past dates from today date with Material ui reactjs? 如何在实现日期选择器中禁用与特定日期相关的过去日期,反之亦然 - How to disable past dates with respect to specific date in materialize datepicker & vice versa 如何在Bootstrap Datepicker中禁用过去的日期 - How to disable past date in Bootstrap Datepicker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM