我正在使用 How display only years in input Bootstrap Datepicker? 上提供的解决方案在日期选择器上只显示年份。
直播DEMO
我的日期选择器具有以下配置:
$("#datepicker").datepicker( {
format: " yyyy", // Notice the Extra space at the beginning
viewMode: "years",
minViewMode: "years"
});
我尝试设置 endDate: '0d'
但没有成功。
如何设置结束日期以防止我使用该解决方案选择 future 年份?
最佳答案
通过将 endDate 属性作为 Date() 默认构造函数检索的当前日期对象传递给我,对我有用。
$("#datepicker").datepicker( {
format: " yyyy", // Notice the Extra space at the beginning
viewMode: "years",
minViewMode: "years",
endDate: new Date()
});
通过使用 JavaScript Date 对象,您应该能够将最大值设置为您想要的任何年份内的日期。
关于javascript - 限制在 viewMode 设置为年的日期选择器上的选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34336216/