我正试图在所有工作日和星期六的特定时间设置一条弹出消息。应该是相当简单的,我知道这可以使用数组等来完成,但是请耐心地理解我,因为我对此有点陌生。
到目前为止,我拥有的是这样的:
<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");
}任何帮助都将不胜感激。
发布于 2018-11-09 16:17:56
下面是一个混乱的例子,它展示了一个你可以采取的方法.并非所有代码路径都已完成(例如,如果连接时间/分钟已被传递,则将事件连接到明天) but...it确实会在一天中配置好的小时/分钟显示一条消息,如果这一天不是周日的话。
<!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>我希望这能帮到你。
https://stackoverflow.com/questions/53226525
复制相似问题