所以这是我有的代码
var imlocation = "../assets/oldham/";
function ImageArray (n) {
this.length = n;
for (var i =1; i <= n; i++) {
this[i] = ' '
}
}
image = new ImageArray(7);
image[0] = 'sunday.jpg';
image[1] = 'monday.jpg';
image[2] = 'tuesday.jpg';
image[3] = 'wednesday.jpg';
image[4] = 'thursday.jpg';`enter code here`
image[5] = 'friday.png';
image[6] = 'saturday.png';
var currentdate = new Date();
var imagenumber = currentdate.getDay();
document.write('<img src="' + imlocation + image[imagenumber] + '">');`
目前它将改变午夜12点钟的照片但是因为它是一个深夜酒吧,我希望它在早上6点改变,我该怎么做?
答案 0 :(得分:0)
下面的代码会考虑当天的小时,如果是在早上6点之前,代码会显示前一天的图像。
var imlocation = "../assets/oldham/";
function ImageArray (n) {
this.length = n;
for (var i =1; i <= n; i++) {
this[i] = ' '
}
}
image = new ImageArray(7);
image[0] = 'sunday.jpg';
image[1] = 'monday.jpg';
image[2] = 'tuesday.jpg';
image[3] = 'wednesday.jpg';
image[4] = 'thursday.jpg';`enter code here`
image[5] = 'friday.png';
image[6] = 'saturday.png';
var currentdate = new Date();
var imagenumber = currentdate.getDay();
var hour = currentdate.getHours();
if (hour < 6) {
imagenumber = imagenumber - 1;
if (imagenumber == -1) imagenumber = 6;
}
document.write('<img src="' + imlocation + image[imagenumber] + '">');`