我正在努力使用一个脚本,导致过夜开放时间检查器有两个不同的开放时间案例。我写了一个脚本,将时间输入更改为:打开,很快打开,很快关闭等等。
我不确定这个隔夜检查器是否像我写的那样有用,因为当日期发生变化时,例如从星期四到星期五,它会在午夜后显示错误的开放时间..
我在我的脚本(日和小时)中编写了两个静态参数来测试它,但没有任何效果!
你能帮助我解决这个问题吗? 谢谢!
<script type="text/javascript">
var date = new Date();
var day = date.getDay();
var hour = date.getHours();
var day = 2;
var hour = 19;
if (day == 0 | 1 | 2 | 3 | 4 && hour == 18 | 19 | 20 | 21 | 22 | 23 | 0 | 1 | 2) {
var weekday = "day" + day;
var oldHTML = document.getElementById(weekday).innerHTML;
if (hour == 18 || 2) {
if (hour == 18 ){var newHTML = "<p><span class='label label-default'>Bald geöffnet</span></p>"; document.getElementById(weekday).innerHTML = newHTML;}
if (hour == 2 ){var newHTML = "<p><span class='label label-default'>Bald geschlossen</span></p>"; document.getElementById(weekday).innerHTML = newHTML;}
}
else {
var newHTML = "<p><span class='label label-default'>Geöffnet</span></p>";
document.getElementById(weekday).innerHTML = newHTML;
}
} else if (day == 5 | 6 && hour == 18 | 19 | 20 | 21 | 22 | 23 | 0 | 1 | 2 | 3 | 4) {
var weekday = "day" + day;
var oldHTML = document.getElementById(weekday).innerHTML;
if (hour == 18 || 4) {
if (hour == 18 ){var newHTML = "<p><span class='label label-default'>Bald geöffnet</span></p>"; document.getElementById(weekday).innerHTML = newHTML;}
if (hour == 4 ){var newHTML = "<p><span class='label label-default'>Bald geschlossen</span></p>"; document.getElementById(weekday).innerHTML = newHTML;}
}
else {
var newHTML = "<p><span class='label label-default'>Geöffnet</span></p>";
document.getElementById(weekday).innerHTML = newHTML;
}
}
</script>
<div class="col-md-3 col-sm-6 col-xs-12 opening_time">
<h3>Öffnungszeiten</h3>
<ul>
<li>
<p>Montag
<time id="day1" datetime-start="19" datetime-end="3">19.00 - 03:00 Uhr</time>
</p>
</li>
<li>
<p>Dienstag
<time id="day2" datetime-start="19" datetime-end="3">19.00 - 03:00 Uhr</time>
</p>
</li>
<li>
<p>Mittwoch
<time id="day3" datetime-start="19" datetime-end="3">19.00 - 03:00 Uhr</time>
</p>
</li>
<li>
<p>Donnerstag
<time id="day4" datetime-start="19" datetime-end="3">19.00 - 03:00 Uhr</time>
</p>
</li>
<li>
<p>Freitag
<time id="day5" datetime-start="19" datetime-end="5">19.00 - 05:00 Uhr</time>
</p>
</li>
<li>
<p>Samstag
<time id="day6" datetime-start="19" datetime-end="5">19.00 - 05:00 Uhr</time>
</p>
</li>
<li>
<p>Sonn- /Feiertage
<time id="day0" datetime-start="19" datetime-end="3">19.00 - 03:00 Uhr</time>
</p>
</li>
</ul>
</div>
答案 0 :(得分:0)
我清理了代码并在其上做了一些基本的 JS 。
它现在运行完美。请随意使用此片段进行隔夜检查问题..
var date = new Date();
var day = date.getDay();
var hour = date.getHours();
var arrayWorkHour = [18, 19, 20, 21, 22, 23, 0, 1, 2];
var arrayWorkDay = [0, 1, 2, 3, 4];
var arrayFreeHour = [18, 19, 20, 21, 22, 23, 0, 1, 2, 3, 4];
var arrayFreeDay = [5, 6];
var soonOpen = "<p><span class='label label-default'>Bald geöffnet</span></p>";
var soonClose = "<p><span class='label label-default'>Bald geschlossen</span></p>";
var openNow = "<p><span class='label label-default'>Geöffnet</span></p>";
if (($.inArray(day, arrayWorkDay) !== -1) && ($.inArray(hour, arrayWorkHour) !== -1)) {
var weekday = "day" + day;
var listItem = document.getElementById(weekday);
if (hour == 18) {
listItem.innerHTML = soonOpen;
} else if (hour == 2) {
listItem.innerHTML = soonClose;
} else {
listItem.innerHTML = openNow;
}
} else if (($.inArray(day, arrayFreeDay) !== -1) && ($.inArray(hour, arrayFreeHour) !== -1)) {
var weekday = "day" + day;
var listItem = document.getElementById(weekday);
if (hour == 18) {
listItem.innerHTML = soonOpen;
} else if (hour == 4) {
listItem.innerHTML = soonClose;
} else {
listItem.innerHTML = openNow;
}
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-3 col-sm-6 col-xs-12 opening_time">
<h3>Öffnungszeiten</h3>
<ul>
<li>
<p>Montag
<time id="day1" datetime-start="19" datetime-end="3">19.00 - 03:00 Uhr</time>
</p>
</li>
<li>
<p>Dienstag
<time id="day2" datetime-start="19" datetime-end="3">19.00 - 03:00 Uhr</time>
</p>
</li>
<li>
<p>Mittwoch
<time id="day3" datetime-start="19" datetime-end="3">19.00 - 03:00 Uhr</time>
</p>
</li>
<li>
<p>Donnerstag
<time id="day4" datetime-start="19" datetime-end="3">19.00 - 03:00 Uhr</time>
</p>
</li>
<li>
<p>Freitag
<time id="day5" datetime-start="19" datetime-end="5">19.00 - 05:00 Uhr</time>
</p>
</li>
<li>
<p>Samstag
<time id="day6" datetime-start="19" datetime-end="5">19.00 - 05:00 Uhr</time>
</p>
</li>
<li>
<p>Sonn- /Feiertage
<time id="day0" datetime-start="19" datetime-end="3">19.00 - 03:00 Uhr</time>
</p>
</li>
</ul>
</div>
&#13;