datepicker限制当前年 [英] datepicker limit current year

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

问题描述

我有一个datepicker的问题,我想要一个用箭头的用户只能选择一个月的第一个月的最后一天的日期,但它将是动态的,因为如果我们是在2014年,我只能看到2014年的一年。



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

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


解决方案

设置 minDate maxDate

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

链接


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.

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 minDate and maxDate like

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

Link

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

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