作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否有可能在 setTimeout
中捕获每一秒的滴答声。假设我需要在 5 秒后注销用户并显示一条消息,例如在 div
中说“您将在 5 秒内注销”。然后是 4,3,2,1 并在 timeOut
例如:
setTimeout(function(){
$("#myDiv").text("you will be logged out in " + n + " seconds");
//"n" being tick of each second.
},5000)
我在互联网上搜索过此问题,但无处可寻。或者任何可以用 setInterval
为这个场景做的事情也是这里的好点。对此有什么想法或建议吗?
最佳答案
那么你可以使用 setInterval
结合clearInterval
方法:
var n = 5;
var timeoutID = window.setInterval(function() {
// this callback will execute every second until we call
// the clearInterval method
$('#myDiv').text('you will be logged out in ' + n + ' seconds');
n--;
if (n === 0) {
// TODO: go ahead and really log the dude out
window.clearInterval(timeoutID);
}
}, 1000);
关于javascript - 捕获 setTimeout 的滴答,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32159482/
有人知道R中的槽是什么吗? 我没有找到其含义的解释。我得到一个递归定义:“槽函数返回或设置有关对象的各个槽的信息” 帮助将不胜感激,谢谢 -胡同 最佳答案 插槽链接到 S4 对象。槽可以被视为对象的一
我有一个字符串“a.b”,我想替换“.”和 ”_”。 gsub(".","_","a.b") 不能作为 .匹配所有字符。 gsub("\.","_","a.b") 只是给我一个错误。 阅读 ?gsub
我是一名优秀的程序员,十分优秀!