Javascript 在每小时的前10分钟后提醒用户
我试图在每小时10分钟后点击按钮时提醒用户。我尝试了以下代码但未成功:Javascript 在每小时的前10分钟后提醒用户,javascript,Javascript,我试图在每小时10分钟后点击按钮时提醒用户。我尝试了以下代码但未成功: function alert10() { var today = new Date().getHours().getMinutes(); if (today > 10) { alert("You can only access this section within the first 10 minutes of every hour"); } } <li><
function alert10() {
var today = new Date().getHours().getMinutes();
if (today > 10) {
alert("You can only access this section within the first 10 minutes of every hour");
}
}
<li><a href="{{route('sel.sec')}}" onclick="alert10()">Section</a></li>
函数alert10(){
var today=新日期().getHours().getMinutes();
如果(今天>10){
警报(“您只能在每小时的前10分钟内访问此部分”);
}
}
getHours()
获取小时,getMinutes()
获取当前小时的分钟数。把这些都锁起来是没有意义的。(例如,在4:25,它说的是“4.getMinutes()”,但4不是具有这种方法的对象。)
您只需删除
getHours()
,您就会没事。尝试在每小时10分钟后使用SetInterval
设置间隔(您的函数,1000*60*10) 这是我很少建议在javascript前端代码中执行的操作。setInterval()有什么问题?