更改每月的每一天的图像

时间:2015-11-05 09:12:06

标签: jquery

我正在计算圣诞节网络应用程序。想要自动更改一个月中每一天的图像,有没有人知道用Jquery做这个的方法?

1 个答案:

答案 0 :(得分:2)

HTML:

<img src="default_image.png" id="img" />

JavaScript的:

$(document).ready(function(){
    var images = 
                {
                    1 : "image_day1.png",   // 1st of december : "path to image"
                    2 : "image_day2.png",   // 2nd of december : "path to image"
                    3 : "image_day3.png"    // 3rd of december : "path to image"
                    // keep doing this until your final date (probably 24th, 25th or 26th)
                };

    var date = new Date(); // new Date() instance
    var day = date.getDate(); // get current day

    $("#img").attr("src", images[day]);
});

编辑1:日期中的错字.GetDay() - 已修复

编辑2:错误的功能,将date.getDay()更改为date.getDate()