我有一个闰年功能,我希望它慢慢地揭示一个答案,然后在一段时间后慢慢消失。这是我的代码。
function isLeaper() {
var image1 = '../images/yes.png';
var image2 = '../images/no.png';
var year = document.getElementById("isLeaper").value;
var arr = year.split('/');
var splitYear = arr[arr.length - 1];
// 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) {
$('#myDiv').html(year + 'is not a leap year. Sorry!').fadeIn('normal', function() {
$(this).fadeOut();
});
// alert(year + 'is not a leap year. Sorry!');
return "false";
}
if (parseInt(splitYear) % 400 == 0) {
$('#myDiv').html(year + 'is a leap year. Hooray!').fadeIn('normal', function() {
$(this).fadeOut();
});
//alert(splitYear + ' is a leap year. Hooray! ');
return "true";
}
}
if (parseInt(splitYear) % 100 != 0) {
$('#myDiv').html(year + 'is a leap year. Hooray!').fadeIn('normal', function() {
$(this).fadeOut();
});
//alert(splitYear + ' is a leap year. Hooray! ');
return "true";
}
}
if ((parseInt(splitYear) % 4) != 0) {
$('#myDiv').html(year + 'is not a leap year. Sorry!').fadeIn('normal', function() {
$(this).fadeOut();
});
//alert(splitYear + ' is not a leap year. Sorry! ');
return "false";
}
}
if ((parseInt(year) % 4) != 0) {
alert(year + ' is not a leap year. Sorry!');
return "false";
}
我已经在 html 部分声明了一个 div,但什么也没发生。它设置为显示答案,我还想修改 yes 答案以显示图像 yes.png 和 no 答案以显示 no.png 图像。任何帮助将不胜感激。谢谢!