在日期选择器中的日期应该只启用以后的2年和6个月从今天的日期,之后的日期应该被禁用。(它不应该接受当前或过去的日期)
$(document).ready(function () {
$('.datepickerOne').datepicker({
format: 'mm/dd/yyyy',
endDate: '+0d',
autoclose: true
}).on("change", function () {
$("#studentDetailsForm").bootstrapValidator('revalidateField', 'certification_date');
})
});发布于 2018-01-15 08:11:14
$(document).ready(function() {
var expireDate = new Date();
expireDate.setFullYear(expireDate.getFullYear() + 2);
expireDate.setMonth(expireDate.getMonth() + 6)
expireDate.setDate(expireDate.getDate() -1);
$( "#expires" ).datepicker({
maxDate: expireDate,
});
})<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<input name="expires" type="text" id="expires" readonly/>
我使用自定义函数来确定最大日期,这样您就可以指定自己的逻辑来确定哪些是有效日期。
发布于 2018-01-15 08:08:44
正如Surjit 所说,使用minDate和maxDate将其设置为今天之前的无值值,并在未来的30个月内设置为最高值。代码应该类似于:
$(document).ready(function () {
$('.datepickerOne').datepicker({
format: 'mm/dd/yyyy',
minDate: -0,
maxDate: "+30M"
autoclose: true
}).on("change", function () {
$("#studentDetailsForm").bootstrapValidator('revalidateField', 'certification_date');
})
});发布于 2018-01-15 07:50:01
如果您正在使用小部件,那么它有限制日期的选项。
使用minDate和maxDate选项限制可选择日期的范围。
请参阅Jquery https://jqueryui.com/datepicker/#min-max
示例
$( ".selector" ).datepicker({
minDate: new Date(2007, 1 - 1, 1)
});https://stackoverflow.com/questions/48258760
复制相似问题