gpt4 book ai didi

jquery - 将整个表格 append/推送到html中的另一个表格中

转载 作者:行者123 更新时间:2023-11-28 04:45:54 25 4
gpt4 key购买 nike

我有两个这样的表

表一

+----------------------------------------
| just | | Many 1 |
| | Ket |-------------|
| desc | | 1 | 2 | 3 |
+---------------+---------+-------------+
| 01 | Kej | | | |
| |---------|-------------+
| | Rp | | | |
+---------------+------------------------
| 02 | Kej | | | |
| |---------|-------------+
| | Rp | | | |
+---------------+------------------------
| 03 | Kej | | | |
| |---------|-------------+
| | Rp | | | |
+---------------+------------------------
| 04 | Kej | | | |
| |---------|-------------+
| | Rp | | | |
+---------------+------------------------
| 05 | Kej | | | |
| |---------|-------------+
| | Rp | | | |
+---------------+------------------------

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">


<div class="form-group">
<div class="row">
<div class="col-md-12">
<table width="100%" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td rowspan="2" >Tgl. Group Temuan</td>
<td rowspan="2">Ket</td>
<td colspan="3">Temuan Pemeriksaan (TP)</td>

</tr>
<tr>
<td>TP s/d Bulan Lalu</td>
<td>TP Bulan ini</td>
<td>TP s/d Bulan ini</td>

</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">01</td>
<td>Kejadian</td>
<td ></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Rp</td>
<td></td>
<td></td>
<td></td>

<tr>
<tr>
<td rowspan="2">05</td>
<td>Kejadian</td>
<td ></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Rp</td>
<td></td>
<td></td>
<td></td>
<tr>
<tr>
<td rowspan="2">02</td>
<td>Kejadian</td>
<td ></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Rp</td>
<td></td>
<td></td>
<td></td>
<tr>
<tr>
<td rowspan="2">03</td>
<td>Kejadian</td>
<td ></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Rp</td>
<td></td>
<td></td>
<td></td>
<tr>
<tr>
<td rowspan="2">04</td>
<td>Kejadian</td>
<td ></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Rp</td>
<td></td>
<td></td>
<td></td>
<tr>
</tbody>
</table>
</div>
</div>
</div>

表2

+-------------------------------------------+
| just | | Many 2 |
| | Ket |-----------------|
| desc | | 1 | 2 | 3 |
+---------------+---------+-----------------+
| 01 | Kej | | | |
| |---------|-----------------+
| | Rp | | | |
+---------------+---------------------------+
| 02 | Kej | | | |
| |---------|-----------------+
| | Rp | | | |
+---------------+---------------------------+
| 03 | Kej | | | |
| |---------|-----------------+
| | Rp | | | |
+---------------+---------------------------+
| 04 | Kej | | | |
| |---------|-----------------+
| | Rp | | | |
+---------------+---------------------------+
| 05 | Kej | | | |
| |---------|-----------------+
| | Rp | | | |
+---------------+---------------------------+

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">


<div class="form-group">
<div class="row">
<div class="col-md-12">
<table width="100%" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td rowspan="2" >Tgl. Group Temuan</td>
<td rowspan="2">Ket</td>

<td colspan="3">TP yang ditindak lanjuti (TP)</td>
<td rowspan="2">TPB s/d Bulan Ini</td>
</tr>
<tr>
<td>TP s/d Bulan Lalu</td>
<td>TP Bulan ini</td>
<td>SUB TOTAL</td>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">01</td>
<td>Kejadian</td>
<td ></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Rp</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td rowspan="2">05</td>
<td>Kejadian</td>
<td ></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Rp</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td rowspan="2">02</td>
<td>Kejadian</td>
<td ></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Rp</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td rowspan="2">03</td>
<td>Kejadian</td>
<td ></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Rp</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td rowspan="2">04</td>
<td>Kejadian</td>
<td ></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Rp</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>

</table>
</div>
</div>
</div>

所以我必须将表 2 合并到表 1 中,我需要将表 2 的第三列到第五列的数据放入表 1 的第五列的下一列,就像下面的代码一样。

表一+表二

+---------------------------------------------------------+
| just | | Many 1 | Many 2 |
| | Ket |-------------|-----------------|
| desc | | 1 | 2 | 3 | 1 | 2 | 3 |
+---------------+---------+-------------+-----------------+
| 01 | Kej | | | | | | |
| |---------|-------------+-----------------+
| | Rp | | | | | | |
+---------------+-----------------------------------------+
| 02 | Kej | | | | | | |
| |---------|-------------+-----------------+
| | Rp | | | | | | |
+---------------+-----------------------------------------+
| 03 | Kej | | | | | | |
| |---------|-------------+-----------------+
| | Rp | | | | | | |
+---------------+-----------------------------------------+
| 04 | Kej | | | | | | |
| |---------|-------------+-----------------+
| | Rp | | | | | | |
+---------------+-----------------------------------------+
| 05 | Kej | | | | | | |
| |---------|-------------+-----------------+
| | Rp | | | | | | |
+---------------+-----------------------------------------+

有人可以帮我解决这个问题吗,我不知道如何像我期望的那样获取表 2 数据列并将其插入表 1 中?

最佳答案

我的 jQuery 解决方案

var el = $("#table2 thead tr:eq(0) td:eq(2)").clone();
$("#table1 thead tr:eq(0)").append(el);

$("#table2 thead tr:eq(1) td").each(function () {
$("#table1 thead tr:eq(1)").append($(this).clone());
});

$('#table2 tbody tr').each(function (index) {
$(this).find('td:nth-last-child(2), td:nth-last-child(3), td:nth-last-child(4)').each(function () {
$("#table1 tbody").find("tr:eq(" + index + ")").append($(this).clone());
});
});

演示: https://plnkr.co/edit/4moGtn?p=preview

JavaScript 解决方案

var table1 = document.getElementById('table1');
var table2 = document.getElementById('table2');

var cell = (table2.tHead.rows[0].cells[2]).cloneNode(true);
table1.tHead.rows[0].appendChild(cell);

for(var i = 0, cells = table2.tHead.rows[1].cells; i < cells.length; i++) {
table1.tHead.rows[1].appendChild( cells[i].cloneNode(true) );
}

for(var i = 0, rows = table2.tBodies[0].rows; i < rows.length; i++) {
var cells = rows[i].cells, rowTable1 = table1.tBodies[0].rows[i];

if(i%2)
rowTable1.appendChild(cells[1].cloneNode(true));

rowTable1.appendChild(cells[2].cloneNode(true));
rowTable1.appendChild(cells[3].cloneNode(true));

if(i%2 == 0)
rowTable1.appendChild(cells[4].cloneNode(true));
}

演示: https://plnkr.co/edit/z67BEo?p=preview

关于jquery - 将整个表格 append/推送到html中的另一个表格中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46355970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com