gpt4 book ai didi

jQuery : Merge column of table

转载 作者:行者123 更新时间:2023-11-28 01:20:27 25 4
gpt4 key购买 nike

我想合并下一个表格的最后一列的单元格具有相同的文本:

enter image description here

我有这段代码,但它会检查相邻行的单元格:

<script language="javascript" type="text/javascript">
$(document).ready(function () {

$('#sample_1 tbody tr:nth-child(4) td:nth-child(4)').each(function(){
alert( $(this).text());

var colSpan=1;
while( $(this).text() == $(this).next().text() ){

$(this).next().remove();
colSpan++;
}
$(this).attr('colSpan',colSpan);
});
});
</script>

这是表格 HTML 的代码源:

<table class="table table-striped table-bordered dataTable TF" id="sample_1" aria-describedby="sample_1_info">
<tbody role="alert" aria-live="polite" aria-relevant="all">
<tr class="fltrow">
<td colspan="4">
<input id="flt0_sample_1" type="text" ct="0" class="single_flt">
</td>
</tr>
<tr class="gradeX odd">
</tr>
<tr role="row">
<th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Username: activate to sort column ascending" style="width: 231px;">Nom</th>
<th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Username: activate to sort column ascending" style="width: 231px;">Prénom</th>
<th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Username: activate to sort column ascending" style="width: 231px;">Numéro Teléphone</th>
<th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Username: activate to sort column ascending" style="width: 231px;">heure de rdv</th>
</tr>
<tr role="row">
<td class="hidden-phone ">
MOSTEFAOui
</td>
<td class="hidden-phone ">
MAiNE
</td>
<td class="hidden-phone ">
0555122844
</td>
<td class="hidden-phone " colspan="1">
09:00
</td>
</tr>
<tr role="row">
<td class="hidden-phone ">
ADJOUT
</td>
<td class="hidden-phone ">
ABDELKADER
</td>

<td class="hidden-phone ">
0775522355
</td>
<td class="hidden-phone ">
10:00
</td>
</tr>
<tr role="row">
<td class="hidden-phone ">
SANAD
</td>
<td class="hidden-phone ">
MILOUD
</td>

<td class="hidden-phone ">
0661225412
</td>
<td class="hidden-phone ">
10:00
</td>
</tr>
<tr role="row">
<td class="hidden-phone ">
ACHAOUR
</td>
<td class="hidden-phone ">
MOHAMED
</td>

<td class="hidden-phone ">
0555122265
</td>
<td class="hidden-phone ">
10:00
</td>
</tr>
<tr role="row">
<td class="hidden-phone ">
TARFAUI
</td>
<td class="hidden-phone ">
MORAD
</td>

<td class="hidden-phone ">
0788745211
</td>
<td class="hidden-phone ">
10:00
</td>
</tr>
<tr role="row">
<td class="hidden-phone ">
TANEM
</td>
<td class="hidden-phone ">
LAKHDAR
</td>

<td class="hidden-phone ">
0666115487
</td>
<td class="hidden-phone ">
11:00
</td>
</tr>
</tbody>
</table>

最佳答案

这不是最优雅的解决方案,但它确实有效。

我在您的第 4 列中添加了一个名为“heure”的类

<td class="heure">11:00</td>

以及对您的 JS 的以下更改

<script language="javascript" type="text/javascript">
$(document).ready(function () {

var topMatchTd;
var previousValue = "";
var rowSpan = 1;

$('.heure').each(function(){

if($(this).text() == previousValue)
{
rowSpan++;
$(topMatchTd).attr('rowspan',rowSpan);
$(this).remove();
}
else
{
topMatchTd = $(this);
rowSpan = 1;
}

previousValue = $(this).text();
});
});
</script>

关于jQuery : Merge column of table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34158092/

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