我正在尝试在某些英国时间在Web应用程序中显示某些字符串。这带来了多个问题,首先要确保该应用程序在英国时间而不是仅在用户所在位置显示这些项目,我认为我已经对此进行了分类。
我的问题是我的交换机仅显示else语句,并且似乎忽略了else if。情况很好。
我确定这很简单,但我看不到。
window.onload = function name(){
var date = new Date();
var d = date.getUTCDay();
var t = new Date()
var h = t.getUTCHours();
var adjtime = (((new Date().getTimezoneOffset * -1)/60)+h);
var shows = [
'String'
'String'
'String'
'String'
'String'
'String'
'String'
'String'
'String'
];
var currentShow;
var nextShow;
switch (d) {
case 0:
if(adjtime >= 00 && adjtime <= 02){ currentShow = shows[0]; nextShow = shows[5];
}else if(adjtime >= 02 && adjtime <= 03){ currentShow = shows[5]; nextShow = shows[6];
}else if(adjtime >= 03 && adjtime <= 04){ currentShow = shows[6]; nextShow = shows[0];
}else if(adjtime >= 04 && adjtime <= 10){ currentShow = shows[0]; nextShow = shows[3];
}else if(adjtime >= 10 && adjtime <= 11){ currentShow = shows[3]; nextShow = shows[4];
}else if(adjtime >= 11 && adjtime <= 12){ currentShow = shows[4]; nextShow = shows[0];
}else if(adjtime >= 12 && adjtime <= 17){ currentShow = shows[0]; nextShow = shows[3];
}else if(adjtime >= 17 && adjtime <= 18){ currentShow = shows[3]; nextShow = shows[0];
}else if(adjtime >= 18 && adjtime <= 20){ currentShow = shows[0]; nextShow = shows[1];
}else if(adjtime >= 20 && adjtime <= 21){ currentShow = shows[1]; nextShow = shows[2];
}else if(adjtime >= 21 && adjtime <= 22){ currentShow = shows[2]; nextShow = shows[0];
}else{ currentShow = shows[0]; nextShow = shows[1];}
break;
case 1:
if(adjtime >= 00 && adjtime <= 02){ currentShow = shows[0]; nextShow = shows[1];
}else if(adjtime >= 02 && adjtime <= 03){ currentShow = shows[1]; nextShow = shows[2];
}else if(adjtime >= 03 && adjtime <= 04){ currentShow = shows[2]; nextShow = shows[0];
}else if(adjtime >= 04 && adjtime <= 10){ currentShow = shows[0]; nextShow = shows[3];
}else if(adjtime >= 10 && adjtime <= 11){ currentShow = shows[3]; nextShow = shows[4];
}else if(adjtime >= 11 && adjtime <= 12){ currentShow = shows[4]; nextShow = shows[0];
}else if(adjtime >= 12 && adjtime <= 17){ currentShow = shows[0]; nextShow = shows[3];
}else if(adjtime >= 17 && adjtime <= 18){ currentShow = shows[3]; nextShow = shows[0];
}else if(adjtime >= 18 && adjtime <= 20){ currentShow = shows[0]; nextShow = shows[7];
}else if(adjtime >= 20 && adjtime <= 21){ currentShow = shows[7]; nextShow = shows[8];
}else if(adjtime >= 21 && adjtime <= 22){ currentShow = shows[8]; nextShow = shows[0];
}else{ currentShow = shows[0];
nextShow = shows[7];}
break;
case 2:
if(adjtime >= 00 && adjtime <= 02){ currentShow = shows[0]; nextShow = shows[7];
}else if(adjtime >= 02 && adjtime <= 03){ currentShow = shows[7]; nextShow = shows[8];
}else if(adjtime >= 03 && adjtime <= 04){ currentShow = shows[8]; nextShow = shows[0];
}else if(adjtime >= 04 && adjtime <= 10){ currentShow = shows[0]; nextShow = shows[1];
}else if(adjtime >= 10 && adjtime <= 11){ currentShow = shows[1]; nextShow = shows[2];
}else if(adjtime >= 11 && adjtime <= 12){ currentShow = shows[2]; nextShow = shows[0];
}else if(adjtime >= 12 && adjtime <= 17){ currentShow = shows[0]; nextShow = shows[4];
}else if(adjtime >= 17 && adjtime <= 18){ currentShow = shows[4]; nextShow = shows[0];
}else if(adjtime >= 18 && adjtime <= 20){ currentShow = shows[0]; nextShow = shows[3];
}else if(adjtime >= 20 && adjtime <= 21){ currentShow = shows[3]; nextShow = shows[4];
}else if(adjtime >= 21 && adjtime <= 22){ currentShow = shows[4]; nextShow = shows[0];
}else{ currentShow = shows[0]; nextShow = shows[1];}
break;
case 3:
if(adjtime >= 00 && adjtime <= 02){ currentShow = shows[0]; nextShow = shows[3];
}else if(adjtime >= 02 && adjtime <= 03){ currentShow = shows[3]; nextShow = shows[4];
}else if(adjtime >= 03 && adjtime <= 04){ currentShow = shows[4]; nextShow = shows[0];
}else if(adjtime >= 04 && adjtime <= 10){ currentShow = shows[0]; nextShow = shows[7];
}else if(adjtime >= 10 && adjtime <= 11){ currentShow = shows[7]; nextShow = shows[8];
}else if(adjtime >= 11 && adjtime <= 12){ currentShow = shows[8]; nextShow = shows[0];
}else if(adjtime >= 12 && adjtime <= 17){ currentShow = shows[0]; nextShow = shows[3];
}else if(adjtime >= 17 && adjtime <= 18){ currentShow = shows[3]; nextShow = shows[0];
}else if(adjtime >= 18 && adjtime <= 20){ currentShow = shows[0]; nextShow = shows[1];
}else if(adjtime >= 20 && adjtime <= 21){ currentShow = shows[1]; nextShow = shows[2];
}else if(adjtime >= 21 && adjtime <= 22){ currentShow = shows[2]; nextShow = shows[0];
}else{ currentShow = shows[0]; nextShow = shows[1];}
break;
case 4:
if(adjtime >= 00 && adjtime <= 02){ currentShow = shows[0]; nextShow = shows[1];
}else if(adjtime >= 02 && adjtime <= 03){ currentShow = shows[1]; nextShow = shows[2];
}else if(adjtime >= 03 && adjtime <= 04){ currentShow = shows[2]; nextShow = shows[0];
}else if(adjtime >= 04 && adjtime <= 10){ currentShow = shows[0]; nextShow = shows[3];
}else if(adjtime >= 10 && adjtime <= 11){ currentShow = shows[3]; nextShow = shows[4];
}else if(adjtime >= 11 && adjtime <= 12){ currentShow = shows[4]; nextShow = shows[0];
}else if(adjtime >= 12 && adjtime <= 17){ currentShow = shows[0]; nextShow = shows[4];
}else if(adjtime >= 17 && adjtime <= 18){ currentShow = shows[4]; nextShow = shows[0];
}else if(adjtime >= 18 && adjtime <= 20){ currentShow = shows[0]; nextShow = shows[7];
}else if(adjtime >= 20 && adjtime <= 21){ currentShow = shows[7]; nextShow = shows[8];
}else if(adjtime >= 21 && adjtime <= 22){ currentShow = shows[8]; nextShow = shows[0];
}else{ currentShow = shows[0]; nextShow = shows[7]; }
break;
case 5:
if(adjtime >= 00 && adjtime <= 02){ currentShow = shows[0]; nextShow = shows[7];
}else if(adjtime >= 02 && adjtime <= 03){ currentShow = shows[7]; nextShow = shows[8];
}else if(adjtime >= 03 && adjtime <= 04){ currentShow = shows[8]; nextShow = shows[0];
}else if(adjtime >= 04 && adjtime <= 10){ currentShow = shows[0]; nextShow = shows[1];
}else if(adjtime >= 10 && adjtime <= 11){ currentShow = shows[1]; nextShow = shows[2];
}else if(adjtime >= 11 && adjtime <= 12){ currentShow = shows[2]; nextShow = shows[0];
}else if(adjtime >= 12 && adjtime <= 17){ currentShow = shows[0]; nextShow = shows[3];
}else if(adjtime >= 17 && adjtime <= 18){ currentShow = shows[3]; nextShow = shows[0];
}else if(adjtime >= 18 && adjtime <= 20){ currentShow = shows[0]; nextShow = shows[3];
}else if(adjtime >= 20 && adjtime <= 21){ currentShow = shows[3]; nextShow = shows[4];
}else if(adjtime >= 21 && adjtime <= 22){ currentShow = shows[4]; nextShow = shows[0];
}else{ currentShow = shows[0]; nextShow = shows[3]; }
break;
case 6:
if(adjtime >= 00 && adjtime <= 02){ currentShow = shows[0]; nextShow = shows[3];
}else if(adjtime >= 02 && adjtime <= 03){ currentShow = shows[3]; nextShow = shows[4];
}else if(adjtime >= 03 && adjtime <= 04){ currentShow = shows[4]; nextShow = shows[0];
}else if(adjtime >= 04 && adjtime <= 10){ currentShow = shows[0]; nextShow = shows[7];
}else if(adjtime >= 10 && adjtime <= 11){ currentShow = shows[7]; nextShow = shows[8];
}else if(adjtime >= 11 && adjtime <= 12){ currentShow = shows[8]; nextShow = shows[0];
}else if(adjtime >= 12 && adjtime <= 17){ currentShow = shows[0]; nextShow = shows[4];
}else if(adjtime >= 17 && adjtime <= 18){ currentShow = shows[4]; nextShow = shows[0];
}else if(adjtime >= 18 && adjtime <= 20){ currentShow = shows[0]; nextShow = shows[5];
}else if(adjtime >= 20 && adjtime <= 21){ currentShow = shows[5]; nextShow = shows[6];
}else if(adjtime >= 21 && adjtime <= 22){ currentShow = shows[6]; nextShow = shows[0];
}else{ currentShow = shows[0]; nextShow = shows[5]; }
break;
}
document.getElementById("current-show").innerHTML = currentShow;
document.getElementById("next-show").innerHTML = nextShow;
}
哪个开关?所有?还有什么呢?还全部吗?您的var数组仅包含“字符串”。
因此它在所有情况下都只显示'String'。