簡體   English   中英

如何在沒有Jquery第一列的情況下獲取表的所有組件?

[英]How to get all the components of the table without the first column in Jquery?

你好我的辦公室接下來,我碰巧有一個用html生成的表,但我想捕獲表的所有結構而不考慮整個第一列,直到現在只能設法捕獲變量中的所有組件,但我需要改進它以捕獲除表的第一列之外的所有列。

html的

<table border="1" id="tblConsulta">
    <thead>
        <tr>
            <th>Eliminar</th>
            <th>Dependencia</th>
            <th>UU.OO</th>
            <th>Documento</th>
            <th>Reg</th>
            <th>Responsable</th>
            <th>Fecha Inicio</th>
            <th>Fecha Fin</th>
            <th>Fecha Autoriz</th>
            <th>Estado</th>
            <th>Motivo</th>
        </tr>
    </thead>
    <tr>
        <td><input class="editor-active" value="74" disabled="" type="checkbox" /></td>   
        <td>1</td>
        <td>2</td>
        <td>3</td>
        <td>4</td>
        <td>5</td>
        <td>6</td>
        <td>7</td>
        <td>8</td>
        <td>9</td>
        <td>10</td>
    </tr>
</table>

JavaScript的

var output = '';

$("[id=tblConsulta]").each(function() {
    output += $(this).find("thead").html();
    $('#tblConsulta tbody tr').each(function() {
        var j = 0;
        output += '<tr class="">';
        $.each(this.cells, function() {
            j++;
            if (j < 12) {
                if (j == 5) {
                    output += '<td class="date">';
                } else if (j == 3) {
                    output += '<td class="number">';
                } else {
                    output += '<td class="text">';
                    output += $(this).html();
                    output += '</td>';
                }
            }
        });
        output += '</tr>';
    });
});

console.log(output);

我希望你可以幫助我,我的想法是捕獲chexbox不想在鏈中標記,因為那時我想在報告中打印它。

我也發布了jsFiddle: https ://jsfiddle.net/movboj2m/

使用tblConsulta tr:gt(1) gt選擇器: https//api.jquery.com/gt-selector/

首先保存后,直接嘗試從表中刪除第一列。 然后在打印完日志后,將表格放回原來的狀態,即:

 var output = ''; var saveTable = $("table").html(); $("table").find("th:first").remove(); $("table").find("tr").each(function() { $(this).find("td:first").remove(); }); $("[id=tblConsulta]").each(function() { output += $(this).find("thead").html(); $('#tblConsulta tbody tr').each(function() { var j = 0; output += '<tr class="">'; $.each(this.cells, function() { j++; if (j < 12) { if (j == 5) { output += '<td class="date">'; } else if (j == 3) { output += '<td class="number">'; } else { output += '<td class="text">'; output += $(this).html(); output += '</td>'; } } }); output += '</tr>'; }); }); console.log(output); $("table").html(saveTable); 
  .title{ font-weight:bold; } .index { height: 30px; width: 40px; display: inline-block; border: 1px solid white; background-color: cadetblue; color: black; text-align: center; line-height: 30px; } .prev { height: 30px; width: 40px; display: inline-block; border: 1px solid white; background-color: cadetblue; color: black; text-align: center; line-height: 30px; } .next { height: 30px; width: 40px; display: inline-block; border: 1px solid white; background-color: cadetblue; color: black; text-align: center; line-height: 30px; } .clicked{ height: 30px; width: 40px; display: inline-block; border: 1px solid black; background-color: #993333; color: white; text-align: center; line-height: 30px; } .enter{ color: white; border: 1px solid black; } #result1{ margin-top: 10px; margin-left: 300px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table border="1" id="tblConsulta"> <thead> <tr> <th>Eliminar</th> <th>Dependencia</th> <th>UU.OO</th> <th>Documento</th> <th>Reg</th> <th>Responsable</th> <th>Fecha Inicio</th> <th>Fecha Fin</th> <th>Fecha Autoriz</th> <th>Estado</th> <th>Motivo</th> </tr> </thead> <tr> <td><input class="editor-active" value="74" disabled="" type="checkbox" /></td> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <td>6</td> <td>7</td> <td>8</td> <td>9</td> <td>10</td> </tr> </table> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM