慕碼人2483693
2023-04-14 16:37:35
我希望實(shí)現(xiàn)以下目標(biāo):如果是星期六或星期日,則顯示我們已關(guān)閉頁(yè)面。如果不是星期六或星期日:.如果在工作時(shí)間以外(不是上午 9 點(diǎn)到中午 12 點(diǎn)之間),顯示我們已關(guān)閉頁(yè)面。.如果是在工作時(shí)間內(nèi),顯示我們開放的頁(yè)面。這是代碼:<html><head><TITLE>Golborne Patient Booking Portal </TITLE><script language="JavaScript" type="text/javascript">function ampmRedirect() { var currentTime = new Date(); var currentHour = currentTime.getHours(); var d = new Date(); var n = d.getDay(); if (n == 0) || (n == 6){ // if Saturday or Sunday window.location.href = "closed.html"; // we are closed } else { // if it is any other day if ((currentHour < 8) || (currentHour > 11)) { // if outside of working hours (8am to noon) window.location.href = "closed.html"; // we are closed } else { // anything else (not weekday or within the times) window.location.href = "open.html"; // we are open } }}</script></head><body onload="ampmRedirect()"></body></html>我哪里錯(cuò)了?
1 回答

開滿天機(jī)
TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊
除了條件表達(dá)式周圍缺少的括號(hào)外,您還可以對(duì)日期和時(shí)間進(jìn)行一次檢查,然后分配一個(gè)結(jié)束頁(yè)面或另一個(gè)目標(biāo)。
function ampmRedirect() {
var date = new Date(),
time = date.getHours(),
day = date.getDay();
window.location.href = day === 0 || day === 6 || time < 8 || time > 11
? "closed.html"
: "https://golborne.abtrace-cloud.com";
}
<body onload="ampmRedirect()">
添加回答
舉報(bào)
0/150
提交
取消