日期选择器 minDate 今天和 maxDate 31 Dec 明年 [英] Datepicker minDate today and maxDate 31 Dec Next year

查看:27
本文介绍了日期选择器 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

最后将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
  });
});

这篇关于日期选择器 minDate 今天和 maxDate 31 Dec 明年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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