欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

bootstrap中table隐藏后显示问题

程序员文章站 2024-02-17 14:17:04
...

开始的时候先把table隐藏了,由于判断条件让它显示,结果出现错位的问题。

//前台代码:

<h3 id="faultanalysis-head" class="text-center" style="display:none"><strong>faultanalysis-table</strong></h3>
<table id="faultanalysis-table" data-height="300" style="display:none"></table>
//后台代码:

if (resp.data.gch_faultanalysis.length!=0) {
                  console.log("gch_faultanalysis不为空!");
                  element.find("#faultanalysis-head").css("display","block");
                  element.find("#faultanalysis-table").css("display","block");
                  element.find("#faultanalysis-table").bootstrapTable({
                      columns:resp.data.faultanalysisVar,
                      pagination:"true",
                      //sidePagination:"client",
                      search:"true",
                      clickToSelect: true,
                      data: resp.data.gch_faultanalysis,
                      singleSelect:"true",
                      showColumns:"false",
                      showRefresh:"true",
                      showToggle:"true",
                      maintainSelected:"true",
                      //height:"413"
                    });
                }


出现如下的错误显示:

bootstrap中table隐藏后显示问题


经过查找分析,只需要将上面代码中标红的block就好了,而且这个不会对<h>产生影响。修改后代码如下:
//前台代码:

<h3 id="faultanalysis-head" class="text-center" style="display:none"><strong>faultanalysis-table</strong></h3>
<table id="faultanalysis-table" data-height="300" style="display:none"></table>

//后台代码:

if (resp.data.gch_faultanalysis.length!=0) {
                  console.log("gch_faultanalysis不为空!");
                  element.find("#faultanalysis-head").css("display","block");
                  element.find("#faultanalysis-table").css("display","");
                  element.find("#faultanalysis-table").bootstrapTable({
                      columns:resp.data.faultanalysisVar,
                      pagination:"true",
                      //sidePagination:"client",
                      search:"true",
                      clickToSelect: true,
                      data: resp.data.gch_faultanalysis,
                      singleSelect:"true",
                      showColumns:"false",
                      showRefresh:"true",
                      showToggle:"true",
                      maintainSelected:"true",
                      //height:"413"
                    });
                }

修改后的截图如下:

bootstrap中table隐藏后显示问题