yearRange - 日期选择器

发布于 2025-01-02 14:49:51 字数 633 浏览 3 评论 0原文

好吧,我有一个表格,其中一个字段是年龄。因此,我设置了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

下壹個目標 2025-01-09 14:49:51

此处查找yearRange选项的工作原理。

您想要通过执行类似“c-nn:c+nn”的操作来设置相对于当前所选年份的yearRange

相应地更新您的初始化:

$('input').datepicker({
  dateFormat: 'dd/mm/yy',
  changeMonth: true,
  changeYear: true,
  showOn: 'button',
  yearRange: 'c-50:c',
})

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:

$('input').datepicker({
  dateFormat: 'dd/mm/yy',
  changeMonth: true,
  changeYear: true,
  showOn: 'button',
  yearRange: 'c-50:c',
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文