gpt4 book ai didi

javascript - Jquery Datepicker ToDate 大于或等于 FromDate

转载 作者:行者123 更新时间:2023-11-29 10:41:35 25 4
gpt4 key购买 nike

我有一个要求,我需要两个日期选择器来输入起始日期和截止日期。截止日期应该大于或等于起始日期(选择起始日期后,所有以前的日期都应该在第二个 Datepiker 中禁用)。也from date 和 todate 应该仅来自当年。我如何使用 jquery 日期选择器配置来做同样的事情。目前我正在创建这样的日期 pikers

     $(document).on('click', '#From', function () {
$(this).datepicker({ dateFormat: 'dd/mm/yy', changeMonth: true, yearRange: new Date().getFullYear().toString() + ':' + new Date().getFullYear().toString(), changeYear: false });
});

$(document).on('click', '#To', function () {
$(this).datepicker({ dateFormat: 'dd/mm/yy', changeMonth: true, yearRange: new Date().getFullYear().toString() + ':' + new Date().getFullYear().toString(), changeYear: false });
});

谁能帮忙解决这个问题

最佳答案

在不丢失年份限制的情况下执行此操作的方法是:

<script type="text/javascript">
$(function () {
$("#From").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
yearRange: new Date().getFullYear().toString() + ':' + new Date().getFullYear().toString(),
onClose: function (selectedDate) {
$("#To").datepicker("option", "minDate", selectedDate);
}
});
$("#To").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
yearRange: new Date().getFullYear().toString() + ':' + new Date().getFullYear().toString(),
onClose: function (selectedDate) {
$("#From").datepicker("option", "maxDate", selectedDate);
}
});
});
</script>

关于javascript - Jquery Datepicker ToDate 大于或等于 FromDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28064816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com