在 javascript 中有一个小的 if/else 问题。没看懂逻辑。。。
该函数应检查是否存在两个日期,如果不存在则发出警报。如果一切正常,它应该这样说......
function update_booking() {
//from_date = The date of arrival
//to_date = The date of departure
var alert = ""; //reset alerts
//get variables from booking form input
var from_date = new Date(document.getElementById('from').value);
var to_date = new Date(document.getElementById('to').value);
//if arrival and departure date is present
if(from_date && to_date) {
var alert = "Everything is OK";
}
//if one or two dates are missing
else {
//if arrival and departure dates are missing
if(from_date == 'undefined' || to_date == 'undefined'){
var alert = "Arrival date and departure date are missing";
}
//if from_date is missing update with value from to_date
if(from_date == 'undefined') {
var alert = "Arrival date are missing";
}
//if to_date is missing update with value from from_date
if(from_date == 'undefined') {
var alert = "Departure date are missing";
}
} //end else if one or more date(s) missing
//write alerts
document.getElementById('alert').innerHTML = alert;
}