[英]Check if Minimum interval between time is 2 hours with jQuery
Im using the car rental plugin and need to modify it in a way that if the rental time chosen by customer is less than 2 hours, to give him a message, pop up or any kind of message, that he needs to choose time minimum 2 hours for rental. 我正在使用租车插件,需要对其进行修改,如果客户选择的租车时间少于2小时,则要给他一个消息,弹出窗口或任何形式的消息,他需要选择最短时间2出租时间。
You can see the example here: http://envato.bestsoftinc.net/wp-car/ 您可以在此处查看示例: http : //envato.bestsoftinc.net/wp-car/
I need to make sure that there is at least 2 hour difference between pick up date field and drop off date field, if not, I need to show him message and not let him click on the Search Button. 我需要确保上车日期字段和下车日期字段之间至少相差2个小时,如果没有,我需要向他显示消息,而不要让他单击“搜索”按钮。 Any ideas how I can achieve that with jQuery or Regular Javascript please? 有什么想法可以用jQuery或Regular Javascript实现吗?
Thank you 谢谢
this is the basic logic for it, try implement this with your site. 这是它的基本逻辑,请尝试在您的网站上实施。 i found moment.js is really helpful with js time date obj you can give it a try 我发现moment.js对js时间日期obj真的很有帮助,您可以尝试一下
if($('#checkInDate').value() === $('#checkOutDate').value) [
if both date is the same date, than 如果两个日期是同一日期,则
var checkInTime = $('#checkInTime').value();
var checkOutTime = $('#checkInTime').valeu();
get time value 获得时间价值
if(checkOutTime > checkInTime) {
checkOutTime must be later than checkInTime when it's the same date 同一日期的checkOutTime必须晚于checkInTime
if(checkOutTime - checkInTime > 2) {
if duration is more than 2 than this value is ok 如果持续时间大于2,则此值还可以
alert('ok');
this fail 3rd if statement 这将失败第三个if语句
} else { alert('error must less than 2 '); }
this fail 2nd if statement 这将失败第二个if语句
} else {alert('error checkout must bigger than checkin'); }
end 1st if statement that check for same date 在检查同一日期的if语句结束
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.