setInterval无法处理document.ready
setInterval not working with document.ready
我完全困惑了,因为我不是Javascript初学者。。。
$(document).ready(function(){
var loadtime = 2000;
var loadtimer = setInterval(function(){
loadtime = loadtime - 100;
console.log(loadtime);
}, 100);
});
这对我不起作用。控制台输出为:1900
我希望脚本每100毫秒输出一次当前的loadtime
。
我的错在哪里?
提前谢谢。
它确实有效-请在JSFiddle上查看此演示。
var loadtime = 2000;
var loadtimer = setInterval(function(){
loadtime = loadtime - 100;
console.log(loadtime);
}, 100);
编辑
它不起作用的原因是你打电话给:
clearInterval(loadtimer);
这会在第一次运行后停止您的setInterval
函数。
相关文章:
- jQuery document.ready not working
- jQuery document.ready停止代码
- 停止对document.ready函数的重定向/刷新
- 如果没有document.ready(),我怎么能拥有多个javascript函数呢
- ASPX Jquery 1.11 $(Document).ready(function() {} was skipped
- 为什么不'加载$(document.ready(function)后,单击“工作”
- 从Document.ready中的bundle执行javascript
- 从 document.ready 调用 jQuery 插件抛出 getPreventDefault 错误
- 调用 Document.ready 外部的 AJAX 函数
- jQuery "$(document).ready(function () {" equivalen
- 尝试触发点击document.ready中Bigcommerce Classic Next主题中的产品选项
- document.ready是在async js之后加载的
- 当在document.ready中使用async=true时会发生什么
- 说明ajax何时在document.ready中调用
- 如何在document.ready(function)时运行隐藏函数和动画
- HTML方法未使用Document Ready加载值
- 超越了在document.ready()中编写简单函数
- Javascript on click事件在函数中不起作用,但在document.ready()中起作用
- 为什么document.ready中的事件处理程序函数有效但无效;取出后不起作用
- 在document.ready jquery上运行ajax请求