yearRange - 日期选择器
好吧,我有一个表格,其中一个字段是年龄。因此,我设置了 att YearRange 来解决我的问题。它解决了这些问题。但是我失去了一个功能:
1 - 在设置yearRange之前,当我选择一年时,范围更新为新范围,例如:年份是2012年,yearRange是-10:+10(默认情况下),这样最大的年份是 2022 年,最旧的年份是 2002 年。之后,当我选择 2002 年时,范围会更新:最大的年份是 2012 年,最旧的年份是 2012 年。是 1992.2
- 在我的例子中,我需要设置yearRange来定义一个范围,然后,当我选择一个新的年份时,范围将被更新,例如:首先年份是2012年,yearRange是-50,之后我例如,选择 1962 年,我希望范围更新为至少 50 年。
在我设置yearRange的代码下面:
function load_datepicker(){
$('.datepicker_birth').datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
showOn: 'button',
yearRange: '-50 :c',
Well, I have a form and one field is the age. Because of this I set the att yearRange to solve my problems. And it solve them. However I lost one functionality:
1 - Before I set the yearRange, when I'd select one year the range were updated to a new range, for example: the year is 2012 and yearRange is -10:+10 (by default), this way the biggest year is 2022 and the oldest year is 2002. After that, when I select the year 2002, the range is updated: the biggest will be 2012 and the oldest will be 1992.
2 - In my case, I need to set the yearRange to define a range and then, when I select a new year the range will be updated, like: first the year is 2012 and the yearRange is -50, after I select 1962 and I wish the range was updated to at least 50 years, for example.
Below the code where I set the yearRange:
function load_datepicker(){
$('.datepicker_birth').datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
showOn: 'button',
yearRange: '-50 :c',
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在此处查找yearRange选项的工作原理。
您想要通过执行类似“c-nn:c+nn”的操作来设置相对于当前所选年份的yearRange
相应地更新您的初始化:
Lookup how the yearRange Option works here.
You want to set the yearRange relative to the currently selected year by doing something like "c-nn:c+nn"
Update your initialization accordingly: