0

我有一些表清理工作需要做,但不知道该怎么做。在这种情况下,当现有表 4 达到列限制时,我正在创建新表。

需要进行清理,因为表是使用 tds 在一行中创建的,其样式为style="DISPLAY: none".

 <table style="border-bottom: #000 1px solid; margin-top: 10px; width: 1000px; float: left; border-right: #000 1px solid">
        <tbody>
            <tr class="tableHeader tbsectionheader">
                <td style="display: none" class="flow_header">
                    ALLERGEN SPECIFIC IGE
                </td>
                <td style="display: none" class="flow_header">
                    CLASS
                </td>
                <td style="display: none" class="flow_header">
                    Carbon dioxide 
                </td>
            </tr>
            <tr>
                <td style="display: none" class="flow_data">
                 </td>
                <td style="display: none" class="flow_data">
                 </td>
                <td style="display: none" class="flow_data">
                 </td>
            </tr>
            <tr>
                <td style="display: none" class="flow_data">
                </td>
                <td style="display: none" class="flow_data">
                </td>
                <td style="display: none" class="flow_data">
                </td>
            </tr>
            <tr>
                <td style="display: none" class="flow_data">
                </td>
                <td style="display: none" class="flow_data">
                </td>
                <td style="display: none" class="flow_data">
               </td>
            </tr>
            <tr>
                <td style="display: none" class="flow_data">
                </td>
                <td style="display: none" class="flow_data">
                </td>
                <td style="display: none" class="flow_data">
               </td>
            </tr>
        </tbody>
    </table>

这是生成标记的完整代码,我应该从根本上解决问题(如果所有行都为空,请不要创建表)只是不知道如何去做。如果所有 td 为空但无法正确建立索引,我尝试删除这些行。

仅供参考 - 所有这些标记都正在使用 .net 转换为 pdf

 $(document).ready(function () {
                if (window.opener != null && !window.opener.closed) {
                    var tbl = $get('<%=hfTableId.ClientID%>').value;
                    var tblstring = window.opener.document.getElementById(tbl).value;
                    $("#tblFlowsheet").html(tblstring);
                    $("#divTtableContainer").append($("#tblFlowsheet"));
                    hideEmptyCols();
                    $get('<%=hfFlowsheetTable.ClientID%>').value = $("#divTtableContainer").html();
                    __doPostBack('DoPrint', 'True');
                }
            });

            function hideEmptyCols() {
                var $table = $("#tblFlowsheet")
                var $thead = $('tr.tableHeader', $table).first();
                var isEmpty = new Array();
                $('td', $thead).each(function (i) {
                    var j = i;
                   //select all tds in this column
                    var tds = $(this).parents('table').find('td:nth-child(' + (i + 1) + ')');
                    //check if all the cells in this column are empty
                    if ((tds.length - 1) == tds.filter(':empty').length) {
                        isEmpty[isEmpty.length] = j
                        //tds.remove();
                        //hide header
                        //$(this).remove();
                    }
                });
                for (var x in isEmpty) { $('td:nth-child(' + (isEmpty[x] + 1) + ')').hide(); }
                splitTable($table);
                $('td').each(function () {
                    if ($(this).text() == '') {
                        $(this).html("&nbsp;");
                   }
                });
              }

      function splitTable(table) {
         trs = table.find('tr');
         $('<table>').insertAfter(table);
         var limit = 3;
          if(table.find('tr:first-child>td').length>limit) {
              newTable = table.next('table');
              newTable.attr('style', 'width:1000px;float:left; margin-top: 10px;border-bottom: solid 1px #000; border-right: solid 1px #000;');
              newTable.append('<tbody>');
              trs.each(function () {
                    tr = $(this);
                    clone = tr.clone();
                    clone.html('');
                    newTable.find('tbody').append(clone);
                    lastTr = newTable.find('tr:last-child');
                    lastTr.append($('>:gt('+limit+')',this));
                });
                splitTable(newTable);
            }
        }
4

1 回答 1

0

不确定完全理解你想要什么,但我猜你想删除他们的孩子没有文本的行。如果是这种情况,请使用:

$('tr').filter(function(){
    var containText = true
    $(this).children().each(function(){
        containText = $(this).text().trim().length == 0;
        return containText;
    })
    return containText;
}).remove();

如果三个td都是空的,它将删除tr

于 2013-06-26T14:42:03.397 回答