你好!有一个任务:随着程序的运行,将中间状态显示在一个表格中。有一些代码:
var table = document.getElementById('table');
function wait(ms)
{
var time = new Date().getTime();
while(new Date() - time <= ms){}
}
function run()
{
for(var i=0; i<10; i++)
{
var l = document.createElement('tr');
var e = document.createElement('td');
e.innerText = String(i);
l.appendChild(e);
table.appendChild(l);
wait(100);
}
}
<table id = table>
</table>
<input type="button" value="run" onclick="run()">
在这种情况下,所有信息都会出现,但仅在功能完成后出现。如何让文字在代码中加入的瞬间出现?
1 个回答