0

我有一个闰年功能,我希望它慢慢地揭示一个答案,然后在一段时间后慢慢消失。这是我的代码。

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 图像。任何帮助将不胜感激。谢谢!

4

2 回答 2

0

因为fadeIndiv必须hidden

添加CSS

#myDiv
{
    display:none;
}

然后尝试。

另请阅读fadeIn http://api.jquery.com/fadeIn/

于 2013-03-18T04:35:34.030 回答
0

我做类似的事情:

$('#myDiv').html(year + 'is a leap year. Hooray!').fadeIn(500).delay(1000).fadeOut(500);

@Rohan 也提到了一个好点。应该看到 div 以显示:隐藏在 css 中。

于 2013-03-18T05:25:27.150 回答