[英]Jquery DatePicker YearRange based on current month
我正在使用Jquery的Datepicker,我想知道是否有可能根据当前月份更改yearRange属性。
就我而言,如果月份与11月或12月不同,则将其当年范围
否则是当前年份+ 1
范例1:
本月:4月
.datepicker({
showOn: "button",
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
yearRange: '-12:+0'
范例2:
本月:11月
.datepicker({
showOn: "button",
buttonImage: "../../App_Themes/Samae/images/calendar.png",
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
yearRange: '-12:+1'
谢谢!
jQuery代码
$(function () {
var d = new Date();
var month = d.getMonth();
var range;
if (month == 10 || month == 11) {
range = '-12:+1';
} else {
range = '-12:+0';
}
$('#txtDate').datepicker({
changeMonth: true,
changeYear: true,
yearRange: range
});
});
您可以通过更改条件来检查它的运行情况, if (month == 03 || month == 11)
。
备用
$(function () {
var d = new Date();
var month = d.getMonth();
$('#txtDate').datepicker({
changeMonth: true,
changeYear: true,
yearRange: (month == 10 || month == 11) ? '-12:+1' : '-12:+0'
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.