我想要做的是让我的闰年函数只返回当用户以 MM/DD/YYYY 形式输入日期时的年份值。现在,我只使用一年,但我希望该功能要求用户以该表格输入日期并计算它是否是闰年。如何修改我当前的代码来做到这一点。我已经用 split 方法声明了一个新变量。谢谢!
function isLeaper() {
var year = document.getElementById("isLeaper").value;
var splitYear = year.split ('/');
// 1. If the year is divisible by 4, but not 100.
if ((parseInt(splitYear) % 4) == 0) {
if (parseInt(splitYear) % 100 == 0) {
if (parseInt(splitYear) % 400 != 0) {
alert(year + 'is not a leap year. Sorry!');
return "false";
}
if (parseInt(splitYear) % 400 == 0) {
alert(year + 'is a leap year. Hooray!');
return "true";
}
}
if (parseInt(splitYear) % 100 != 0) {
alert(year + 'is a leap year. Hooray!');
return "true";
}
}
if ((parseInt(splitYear) % 4) != 0) {
alert(year + 'is not a leap year. Sorry!');
return "false";
}
}