我有一个项目,其中包含两个单元格的形式,一个是文本,另一个是日期。如果文本字段和日期字段具有正确的输入来执行新功能,我有 2 个 JS 文件可以验证我想要的每个单元格。如果不显示我在其他 JS 文件中编码的警报消息,我尝试了很多,但我不知道是什么问题?
第一个 JS 文件
export function daysRemaining() {
document.getElementById('search').addEventListener('click', (event) => {
event.preventDefault();
//console.log("I'm there from search form");
const today = new Date(); //today date
const tripDate = new Date(document.getElementById('date').value); //trip date entered by user
if (tripDate > today) {
console.log(
Math.ceil(Math.abs(tripDate - today) / (1000 * 60 * 60 * 24))
);
}
});
}
第二个文件
export function checkDestinationAndDate() {
document.getElementById('search').addEventListener('click', (event) => {
event.preventDefault();
const destination = document.querySelector('#destination').value;
const tripDate = new Date(document.getElementById('date').value);
if (!destination && !Date.parse(tripDate)) {
alert('Enter a destination and a date');
} else if (destination && !Date.parse(tripDate)) {
alert("You didn't choose a date");
} else if (!destination && Date.parse(tripDate)) {
alert("You didn't choose a destination");
} else if (destination && Date.parse(tripDate) < new Date()) {
alert('Please pick a future date');
} else {
console.log(destination);
}
});
}
*第三个JS文件和我要编辑的内容*
import { daysRemaining } from './days_countdown';
import { checkDestinationAndDate } from './destination_date';
export function main() {
document.getElementById('search').addEventListener('click', (event) => {
event.preventDefault();
if (daysRemaining === true && checkDestinationAndDate === true) {
console.log('good work');
} else {
console.log('Failed');
}
});
}
我怎样才能做到这一点?