jQuery UI Datepicker:在< select>中显示所有12个月本年度? [英] jQuery UI Datepicker: Display all 12 months in <select> for current year?

查看:91
本文介绍了jQuery UI Datepicker:在< select>中显示所有12个月本年度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以下选项中使用 jQuery UI Datepicker :

$('#birth_date').datepicker({
        changeMonth: true,
        changeYear: true,
        minDate: new Date(-2206281600*1000),
        maxDate: new Date(1298653687*1000),
        yearRange: '1900:2011'
});

效果很好.月份和年份显示为2个并排的<select>框.问题是,我们只是在2011年2月.因此,当用户输入出生日期(例如12月)时,该月份尚不可用.他们必须先选择年份,然后才能选择月份.

Works pretty well. The month and year are displayed as 2 side-by-side <select> boxes. The problem is, we're only in Feb of 2011. So when the user goes to enter their birth date, to say, Dec, that month isn't available yet. They have to choose their year first before the month becomes selectable.

即使那几个月不是当年的有效选项,我如何才能显示全部12个月?

How can I get into to display all 12 months, even if those months aren't valid options for the current year?

推荐答案

对于仍在寻找的任何人,我最终都使用defaultDate来解决此问题:

For anyone still looking, I ended up using defaultDate to fix this:

$( ".selector" ).datepicker({
  changeMonth: true,
  changeYear: true,
  minDate: '-100Y', //100 Years Old
  maxDate: '0' //Today
  defaultDate: '-1Y', //Default to One Year Ago to show 12 months
  yearRange: '-100:+0' //Show 100 
});

它仍然限制了日期范围,因此将来没有人可以选择日期,并且不依赖用户按特定顺序输入.

It still limits the date range so no one can pick a date in the future, and doesn't rely on the user inputting in a particular order.

这篇关于jQuery UI Datepicker:在&lt; select&gt;中显示所有12个月本年度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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