我正在使用 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">
最佳答案
更改您的初始设置以包括 min
和 max
日期。
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/