jscript/html 在特定时间弹出

jscript/html popup at specifc time

我正在尝试在所有工作日和周六的特定时间设置弹出消息。应该相当简单,我知道这可以使用数组等来完成,但请耐心等待,因为我对此有点陌生。

我目前的情况是这样的:

<script type="text/javascript"> 
var day = day.getday();
var hr = day.getHours();

if ((hr < 10) && (hr > 18) && (day == 1) || (hr < 10) && (hr > 18) && (day == 2) || (hr < 10) && (hr > 18) && (day == 3) || (hr < 10) && (hr > 18) && (day == 4) || (hr < 10) && (hr > 18) && (day == 5))

{
document.write("test");
}

如有任何帮助,我们将不胜感激。

这是一个杂乱的示例,展示了您可以采用的方法...并非所有代码路径都已完成(比如如果配置的 hour/min 是,则连接明天的事件已经过去了) 但是...它确实会在当天的配置 hour/min 显示一条消息,如果那一天不是星期天。

<!DOCTYPE html>
<html>
<head>
</head>
<body>

<script>
    var showPopup = function()
    {
        document.write("test");
        alert("Show Message!");
    };

    var hookupAlert = function(targetHour, targetMin)
    {
        var nextAlert = null;
        var now = new Date();       // Now.
        var day = now.getDay();     // Returns 0-6 where 0=Sunday, 6=Saturday.
        var hr = now.getHours();    // Returns 0-23.
        var min = now.getMinutes(); // Returns 0-59.

        // If a weekday or saturday.
        if(day != 0)
        {
            // Is it before the target hour/min?
            if(hr <= targetHour && min < targetMin)
            {
                nextAlert = new Date(now.getFullYear(), now.getMonth(), now.getDate(), targetHour, targetMin, 0);
            }
            else
            {
                // We've passed the target hour/min for the day...
                // TODO: Possibly determine tomorrow (or if tomorrow is Sunday, the day after).
                console.log("Passed the targetHour & targetMin for the day.");
            }
        }

        if(nextAlert)
        {
            var diffInMs = Math.abs(nextAlert - now);
            window.setTimeout(showPopup, diffInMs);
        }
    };


    // Make the call to hook up the alert at 11:15.
    hookupAlert(11, 15);    // Hour between 0-23, Min between 0-59.


</script>

</body>

希望对您有所帮助。