Datepicker minDate今天和maxDate 31 Dec十二月 [英] Datepicker minDate today and maxDate 31 Dec Next year

查看:245
本文介绍了Datepicker minDate今天和maxDate 31 Dec十二月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试限制今年至明年12月31日之间的日期选择。

Try to limit the date selection between today and 31st Dec of next year.

$(function() {
  $('.public-holiday-date-pick').datepicker({ 
    minDate: '0',
    yearRange: '-0:+1',
    maxDate: ???
    hideIfNoPrevNext: true
  });
});

我应该如何定义maxDate?尝试了很多东西,如31 12 +1,或者只是明年的最后一天,没有起作用。

How should I define maxDate ? tried few things like '31 12 +1', or just 'last day of next year', did not work.

推荐答案

1)首先得到今天的使用

1) First get today's using

var today = new Date();

2)同样设置 lastDate

2) Similarly set the lastDate as below

var lastDate = new Date(today.getFullYear() +1, 11, 31);

lastDate 中的值将为


lastDate =今年12月31日,+1 / code>

最后将 lastDate 设置为 maxDate

Finally set the lastDate as maxDate

var today = new Date();  //Get today's date
var lastDate = new Date(today.getFullYear() +1, 11, 31);  //To get the 31st Dec of next year
$(function() {
  $('.public-holiday-date-pick').datepicker({ 
    minDate: '0',
    yearRange: '-0:+1',
    maxDate: lastDate, //set the lastDate as maxDate
    hideIfNoPrevNext: true
  });
});

这篇关于Datepicker minDate今天和maxDate 31 Dec十二月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆