javascript - Amsul DatePicker - 如何在选择选项中加载年数?

标签 javascript jquery html css

我正在使用 Amsul DatePicker:https://amsul.ca/pickadate.js/date/#selectors而且我无法找出如何在年份下拉列表中加载所需年数。默认情况下,它会在当年的前半年和当年的后半年到来。

所以我想要实现的是我想加载从当前年份回溯 150 年。

寻求帮助。

谢谢

$('.datepicker').pickadate({
  selectYears: 100,
  selectMonths: true,
  min: true
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://hateable-tests.000webhostapp.com/classic.css" rel="stylesheet">
<link href="https://hateable-tests.000webhostapp.com/classic.date.css" rel="stylesheet">
<link href="https://hateable-tests.000webhostapp.com/classic.time.css" rel="stylesheet">
<script src="https://hateable-tests.000webhostapp.com/picker.js"></script>
<script src="https://hateable-tests.000webhostapp.com/legacy.js"></script>
<script src="https://hateable-tests.000webhostapp.com/picker.date.js"></script>
<script src="https://hateable-tests.000webhostapp.com/picker.time.js"></script>

<input name="dob" type="text" class="form-control account-field-input datepicker">

最佳答案

更改您的初始设置以包括 minmax 日期。

var maxDate = new Date();
var minDate = new Date();
minDate.setFullYear( minDate.getFullYear() - 150 );

$('.datepicker').pickadate({
  min: minDate,
  max: maxDate,
  selectYears: 150,
  selectMonths: true
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://hateable-tests.000webhostapp.com/classic.css" rel="stylesheet">
<link href="https://hateable-tests.000webhostapp.com/classic.date.css" rel="stylesheet">
<link href="https://hateable-tests.000webhostapp.com/classic.time.css" rel="stylesheet">
<script src="https://hateable-tests.000webhostapp.com/picker.js"></script>
<script src="https://hateable-tests.000webhostapp.com/legacy.js"></script>
<script src="https://hateable-tests.000webhostapp.com/picker.date.js"></script>
<script src="https://hateable-tests.000webhostapp.com/picker.time.js"></script>

<input name="dob" type="text" class="form-control account-field-input datepicker">

关于javascript - Amsul DatePicker - 如何在选择选项中加载年数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55968879/

相关文章:

jquery - 克隆元素并添加和删除?

php - 只显示最新的 20 个 Sql 表条目?

javascript - 这是普通函数、构造函数还是两者都不是?

javascript - jquery remove 从另一个元素中删除

jquery - jQuery 中使用 hasClass 在元素之间循环

javascript - JQuery - 点击/链接处理程序出现问题

android - XDK - 在不使用 Cordova 的情况下在浏览器中打开链接

javascript - 停止 Div 滚动到另一个 div

javascript - 按钮禁用 - 如何改变外观

javascript - 哪种方式是正确的,为什么?