【发布时间】:2018-12-14 15:19:05
【问题描述】:
在 jquery DataTables 加载之前,短暂且未格式化的表数据加载。我研究并发现很多人说解决方案是用 css 隐藏表,然后用 initComplete 在 jquery 中显示它。我尝试了以下方法,但似乎没有任何效果:
css:
#tblAccount {
visibility:hidden;
}
#tblCustomer {
visibility: hidden;
}
jquery:
$(function () {
$("[id*=tblAccount], [id *= tblCustomer]").prepend($("<thead></thead>").append($(this).find("tr:first"))).DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": true,
"responsive": true,
"dom": 'lBfrtip',
"buttons": ['excel', 'print', 'pdfHtml5'],
"initComplete": function () {
$('#tblAccount').show().css({ visibility: "visible" });
$('#tblCustomer').show().css({ visibility: "visible" });
}
});
})
【问题讨论】:
-
jQuery 的 show() 函数将元素显示属性更改为“块”或等效项。所以你会更幸运地从两者中删除 .css() 部分,并将初始 css 更改为 'display: none' 而不是使用可见性。当您在上面运行代码时会发生什么?
-
我尝试按照您的建议更改 css 为“显示:无”并从 jquery 中删除 css 部分。我得到了相同的结果,没有任何变化。在 DataTables 加载之前,我仍然会在短时间内看到未格式化的表格。清除缓存,结果相同。
-
你在哪里设置 css 以显示:无,是 css 中的吗?
-
是的,我在这样的样式表中显示:#tblAccount { display: none; }