javascript - 如何更新为 javascript/jquery 中的 for 循环的每次迭代显示的 html?

标签 javascript jquery html loops iteration

如何让循环的每次迭代更改 h1?此代码现在仅在完成所有操作后显示 h1 文本。

for (i=0; i<array.length; i++) {
  $("body > h1").text("Processing #" + i);
  // things that take a while to do
}

附加信息:如果我在循环时调整窗口大小,html 会更新。

最佳答案

var array = ['one', 'two', 'three']
var i = 0;

var refreshIntervalId = setInterval(function() {
    length = array.length;
    if (i < (array.length +1)) {
        $("h1").text("Processing #" + i);
    } else {
        clearInterval(refreshIntervalId);
    }
    i++     
}, 1000);

http://jsfiddle.net/3fj9E/

关于javascript - 如何更新为 javascript/jquery 中的 for 循环的每次迭代显示的 html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15123553/

相关文章:

javascript - vue-truncate-filter 不过滤并抛出错误

javascript - 更改新的日期格式

jquery - Bootstrap typeahead - 如何手动设置默认值

php - 如何在显示到 php 中时创建按钮超链接

javascript - 具有与表单属性相同的名称属性的表单元素,隐藏/覆盖 native 表单属性。有解决方法吗?

javascript - 在 jQuery 中将 div 包裹在附加 div 上无法正常工作

javascript - 嵌套 Async ForEach 循环

jQuery Select2 - 从原始选项的选择中获取样式属性

javascript - AJAX 调用未按预期运行

html - 悬停时更改列表项元素符号/数字颜色