Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScriptjQuery逐步显示图像_Javascript_Jquery - Fatal编程技术网

JavaScriptjQuery逐步显示图像

JavaScriptjQuery逐步显示图像,javascript,jquery,Javascript,Jquery,我有一个闰年函数,我希望它慢慢地揭示一个答案,然后在一段时间后慢慢消失。这是我的密码 function isLeaper() { var image1 = '../images/yes.png'; var image2 = '../images/no.png'; var year = document.getElementById("isLeaper").value; var arr = year.s

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

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

对于
fadeIn
您的
div
必须是
隐藏的

加载项CSS

#myDiv
{
    display:none;
}
然后试试看

另请阅读fadeIn

我做了如下事情:

$('#myDiv').html(year + 'is a leap year. Hooray!').fadeIn(500).delay(1000).fadeOut(500);
另外@Rohan提到了一个很好的观点。div应该显示为:隐藏在css中