jQuery DatePicker日历以记住以前的选定日期

发布于 2025-01-27 15:20:13 字数 1925 浏览 2 评论 0原文

我的页面上有2个日期选择器的格式以显示月份和年度。当用户选择月和年时,该页面会根据选择加载数据。所有这些都很好。用户抱怨说,当他们再次单击日历时,选项默认为当前月份,而不是用户先前选择的内容。我已经尝试了一些尝试设置默认日期的选项,而似乎没有用。

这是初始负载时页面的样子。

选择一个月后,用户单击“完成”,页面将加载数据。当用户返回日期选择器时,它显示了当前月,而不是上一个月。

这里应该显示2月作为日历选择器中的一个月。

 //set the date picker default dates
        var startDate = new Date();
        var date = new Date();
        var endDate = new Date(date.setMonth(date.getMonth() + 1));


        //set the top navigation
        $("#InventoryFromDate").datepicker({
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true,
            dateFormat: 'MM yy',
            yearRange: "-5: +00",
            defaultDate: startDate,
            yearRange: "-5: +00",
            onClose: function (selectedDate, inst) {
                $(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
                msophysicalinventory.loaddata(selectedDate, toDate);
            }
        });

        $("#InventoryToDate").datepicker({
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true,
            dateFormat: 'MM yy',
            yearRange: "-5: +00",
            defaultDate: endDate,
            onClose: function (selectedDate, inst) {
                $(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
                var fromDate = $("#InventoryFromDate").val();
                msophysicalinventory.loaddata(fromDate, selectedDate);
            }
        });

如果更改,我如何获取日历选项以显示最后选定的日期?

I have 2 date pickers on my page that are formatted to display month and year. When a user selects the month and year, the page loads data based on the selection. All this works fine. The users are complaining that when they go to click on the calendar again, the options are defaulting to the current month and year and not what the user previously selected. I have tried several option out there regarding trying to set the default date and none seem to work.

Here is what the page looks like on initial load.

enter image description here

After a month is selected and the user has click "Done", the page loads the data. When the user goes back in to the date picker, it is displaying the current month and not the previous selected month.

Here is should be displaying Feb as the month in the calendar selector.

enter image description here

 //set the date picker default dates
        var startDate = new Date();
        var date = new Date();
        var endDate = new Date(date.setMonth(date.getMonth() + 1));


        //set the top navigation
        $("#InventoryFromDate").datepicker({
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true,
            dateFormat: 'MM yy',
            yearRange: "-5: +00",
            defaultDate: startDate,
            yearRange: "-5: +00",
            onClose: function (selectedDate, inst) {
                $(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
                msophysicalinventory.loaddata(selectedDate, toDate);
            }
        });

        $("#InventoryToDate").datepicker({
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true,
            dateFormat: 'MM yy',
            yearRange: "-5: +00",
            defaultDate: endDate,
            onClose: function (selectedDate, inst) {
                $(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
                var fromDate = $("#InventoryFromDate").val();
                msophysicalinventory.loaddata(fromDate, selectedDate);
            }
        });

How do I get the calendar option to show the last selected date if changed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉城 2025-02-03 15:20:13

您需要一种方法可以存储以前选择的日期的某个地方,并且在用户返回日期选择器时需要设置。

//将datePicker设置为2022年5月5日

('#neventoryTodate')。datePicker(“ setDate”,新日期(2022,5,05));

There is one way that you need to store somewhere previously selected date and that need to set when the user goes back for date picker.

//Set DatePicker to May 05, 2022

$('#InventoryToDate').datepicker("setDate", new Date(2022,5,05) );

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文