Daterangepicker:选择日期时如何阻止开始日期和结束日期相同?
我在我的网站上使用 JQuery 的 daterangepicker 插件,使用户能够选择预订房间的入住和退房日期。我已确保用户无法选择任何已经过去的日期,但我的问题是,当用户选择特定日期作为其入住日期时,他们将能够再次选择相同的日期作为其退房日期,这就是我想避免他们这样做。例如,如果他们选择 2022 年 3 月 14 日作为入住日期,则可以再次选择 2022 年 3 月 14 日作为退房日期。
这是我为实现这项工作所做的努力:
$(".checkin").daterangepicker({
autoApply: true,
alwaysShowCalendars: true,
formatDate: 'MM/DD/YYYY', // Format i chose for setting how date should look
startDate: moment(), // I set the starting date to be the current date
endDate: moment().add(1, 'days'), // I set the no of days not to exceed 1 day but it made only the current day selectable
minDate: moment(),
maxDate: moment().add(1, "days"),
clickDate(): function(e) { // I saw this method in the daterangepicker object but it didn't work
console.log("Specified date clicked");
}
});
谁可以帮助我解决这个问题?
I am using JQuery's daterangepicker plugin on my website to enable users to select check-in and check-out dates for booking a room. I have made sure that the user cannot select any date that has already passed but my issue is when the user selects a particular date as their check in date, they would be able to select that same date again as their checkout date and this is what I want to avoid them doing. For example if they select 14th March 2022 as their check in date, they would be able to select 14th March 2022 again as their checkout date.
Here is a what I have done to try make this work:
$(".checkin").daterangepicker({
autoApply: true,
alwaysShowCalendars: true,
formatDate: 'MM/DD/YYYY', // Format i chose for setting how date should look
startDate: moment(), // I set the starting date to be the current date
endDate: moment().add(1, 'days'), // I set the no of days not to exceed 1 day but it made only the current day selectable
minDate: moment(),
maxDate: moment().add(1, "days"),
clickDate(): function(e) { // I saw this method in the daterangepicker object but it didn't work
console.log("Specified date clicked");
}
});
Who can help me out with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不希望用户选择确切的开始和结束日期,那么您可以在daterangerpicker函数中尝试:
avoid
相反,使用下面的代码覆盖相同的日期并通过添加一天使它们连续
If you don't want the user to select the exact start and end date then you can try this in daterangerpicker function:
avoid this
Instead, Use the below code to override the same date and make them consecutive by adding one day