禁用Jquery Ui Datepicker中的未来日期

时间:2022-11-30 09:03:57

I want to disable all the future dates after today in Jquery Ui Datepicker

我想禁用Jquery Ui Datepicker中的所有未来日期

Here is the Demo :

下面是演示:

Code :

代码:

$( "#start_date" ).datepicker(

        { 
            maxDate: '0', 
            beforeShow : function()
            {
                jQuery( this ).datepicker('option','maxDate', jQuery('#end_date').val() );
            },
            altFormat: "dd/mm/yy", 
            dateFormat: 'dd/mm/yy'

        }

);

$( "#end_date" ).datepicker( 

        {
            maxDate: '0', 
            beforeShow : function()
            {
                jQuery( this ).datepicker('option','minDate', jQuery('#start_date').val() );
            } , 
            altFormat: "dd/mm/yy", 
            dateFormat: 'dd/mm/yy'

        }

);

7 个解决方案

#1


65  

Try this

试试这个

 $(function() {
  $( "#datepicker" ).datepicker({  maxDate: new Date() });
 });

Or you can achieve this using as below:

或者你可以这样做:

$(function() {
  $( "#datepicker" ).datepicker({  maxDate: 0 });
});

Reference

参考

DEMO

演示

UPDATED ANSWER

更新后的答案

#2


4  

In my case, I have given this attribute to the input tag

在我的例子中,我将这个属性赋予了input标记

data-date-start-date="0d" data-date-end-date="0d"

data-date-start-date = " 0 d”data-date-end-date = " 0 d”

#3


3  

You can simply do this

你可以这么做。

$(function() {
    $( "#datepicker" ).datepicker({  maxDate: new Date });
  });

JSFiddle

JSFiddle

FYI: while checking the documentation, found that it also accepts numeric values too.

提示:在检查文档时,发现它也接受数值。

Number: A number of days from today. For example 2 represents two days from today and -1 represents yesterday.

日期:几天后。例如2表示从今天开始的两天,-1表示昨天。

so 0 represents today. Therefore you can do this too

0代表今天。因此你也可以这么做

 $( "#datepicker" ).datepicker({  maxDate: 0 });

#4


2  

Change maxDate to current date

将maxDate更改为当前日期

maxDate: new Date()

It will set current date as maximum value.

它将设置当前日期为最大值。

#5


1  

In case you are appending Dtpicker,use the following code

如果您正在添加Dtpicker,请使用以下代码。

$('#enddate').appendDtpicker({
    "dateOnly": true,
    "dateFormat": "YYYY-MM-DD",
    "closeOnSelected": true,
    maxDate: new Date()         
});

#6


0  

This worked for me endDate: "today"

这句话对我很管用:“今天”

  $('#datepicker').datepicker({
        format: "dd/mm/yyyy",
        autoclose: true,
        orientation: "top",
        endDate: "today"

  });

SOURCE

#7


-3  

maxDate: new Date() 

its working fine for me disable with current date in date range picker

它可以在日期范围内为我禁用当前日期选择器

#1


65  

Try this

试试这个

 $(function() {
  $( "#datepicker" ).datepicker({  maxDate: new Date() });
 });

Or you can achieve this using as below:

或者你可以这样做:

$(function() {
  $( "#datepicker" ).datepicker({  maxDate: 0 });
});

Reference

参考

DEMO

演示

UPDATED ANSWER

更新后的答案

#2


4  

In my case, I have given this attribute to the input tag

在我的例子中,我将这个属性赋予了input标记

data-date-start-date="0d" data-date-end-date="0d"

data-date-start-date = " 0 d”data-date-end-date = " 0 d”

#3


3  

You can simply do this

你可以这么做。

$(function() {
    $( "#datepicker" ).datepicker({  maxDate: new Date });
  });

JSFiddle

JSFiddle

FYI: while checking the documentation, found that it also accepts numeric values too.

提示:在检查文档时,发现它也接受数值。

Number: A number of days from today. For example 2 represents two days from today and -1 represents yesterday.

日期:几天后。例如2表示从今天开始的两天,-1表示昨天。

so 0 represents today. Therefore you can do this too

0代表今天。因此你也可以这么做

 $( "#datepicker" ).datepicker({  maxDate: 0 });

#4


2  

Change maxDate to current date

将maxDate更改为当前日期

maxDate: new Date()

It will set current date as maximum value.

它将设置当前日期为最大值。

#5


1  

In case you are appending Dtpicker,use the following code

如果您正在添加Dtpicker,请使用以下代码。

$('#enddate').appendDtpicker({
    "dateOnly": true,
    "dateFormat": "YYYY-MM-DD",
    "closeOnSelected": true,
    maxDate: new Date()         
});

#6


0  

This worked for me endDate: "today"

这句话对我很管用:“今天”

  $('#datepicker').datepicker({
        format: "dd/mm/yyyy",
        autoclose: true,
        orientation: "top",
        endDate: "today"

  });

SOURCE

#7


-3  

maxDate: new Date() 

its working fine for me disable with current date in date range picker

它可以在日期范围内为我禁用当前日期选择器