我有一个包含大约 2000 条记录的 JSON 数组,我需要构建一个表格来显示这些记录中的数据。由于它有大量数据,处理可能会导致浏览器冻结。所以我被要求显示一个进度条指示进度。Javascript 是单线程的,我必须使用 Setinterval 来显示进度。但是在 IE 版本中进度显示不正确,具体取决于数组中的记录数。请帮忙
var g_arr = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
$("#btn").click(function() {
var Loop = 1000;
$("#tbl tbody td").remove();
$("#divProgress").progressbar({
value: 0
});
//window.setTimeout(function(){
for (var i = 0; i < Loop; i++) {
var TR = $("<tr>");
$.each(g_arr, function(index, val) {
var TD = $("<td>");
TD.append(val);
TR.append(TD);
});
window.setTimeout(function() {
$("#divProgress").progressbar({
value: (i / Loop) * 100
});
}, 3000);
$("#tbl tbody").append(TR);
}
//},0);
});
td,
th,
table {
border-color: black;
border-width: thin;
border-style: solid;
border-collapse: collapse;
}
<link href="http://code.jquery.com/ui/1.10.0/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
<div id="divProgress"></div>
<div id="divBody">
<input type="button" id="btn" value="Click Here" />
<table id="tbl">
<thead>
<tr>
<th>
Column1
</th>
<th>
Column2
</th>
<th>
Column3
</th>
<th>
Column4
</th>
<th>
Column5
</th>
<th>
Column6
</th>
<th>
Column7
</th>
<th>
Column8
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
在此处输入代码