setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式。
if (result_i < result.length) {
setTimeout(function() {
for (var j = 0; j < result[result_i].length; j++) {
html = result[result_i][j].text
$(".demos-content-padded").append(html + "<br/>")
}
loading = false;
}, 1000);
// result_i++ //如果 result_i++ 写在这块,会先执行result_i++ ,在执行setTimeout,因为 setTimeout 一秒(1000毫秒)后才执行
// console.log('长度自加后的i= ' + result_i);
}
函数内有setTimeout,result_i++ 不管写在 setTimeout 前面还是后面,都会先执行 result_i++,后执行 setTimeout