日期选择器限制当前年份 [英] datepicker limit current year

查看:19
本文介绍了日期选择器限制当前年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对日期选择器有一个小问题,我希望带箭头的用户只能选择第一个月的第一天和该月的最后一天之间的日期,但它会是动态的,因为如果我们是2014年我只能看到2014年.

I have a little problem with datepicker, I'd want that a user with arrows can only select a date between the first day of the first month and the last day of the month, but it would be dynamic because if we are in 2014 I have to see only year of 2014.

我已经尝试过这种模式,但使用箭头我可以去 2012 或 2014,例如:

I have tried in this mode but with arrows I can go to 2012 or 2014 for example:

$('#check-in').datepicker({ dateFormat: 'dd-mm', changeYear: false, yearRange: "-0:+0", stepYears: 0  });

推荐答案

Set minDatemaxDate like

Set minDate and maxDate like

$(function() {
    var year = (new Date).getFullYear();
    $( "#datepicker" ).datepicker({
        minDate: new Date(year, 0, 1),
        maxDate: new Date(year, 11, 31)
    });
});

链接

这篇关于日期选择器限制当前年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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