gpt4 book ai didi

javascript - 包含文本区域的行跨度表 td

转载 作者:行者123 更新时间:2023-11-28 05:55:48 24 4
gpt4 key购买 nike

到目前为止,我已经能够将表格行与 td 中的文本合并,但文本区域中的文本尚未通过。我的 table

Column1 | column2 | column3 | Column4
--------------------------------------
Assay | Source | label | 3%
-------------------------------------
Assay | Source | label | 10%
-------------------------------------

我想完成什么

Column1 | column2 | column3 | Column4
-------------------------------------- //Note that Column1 has
| | | 3% //no textarea, just td text
Assay - Source - label ----------- //While all the rest have
| | | 10% //textareas in the tds
------------------------------------- // from column 2 - 4

我的这段代码仅适用于没有文本区域的 tds。如何合并具有相同数据的文本区域的行?

function merge() {
$('.result_table').each(function() {
var Column_number_to_Merge = 1;

// Previous_TD holds the first instance of same td. Initially first TD=null.
var Previous_TD = null;
var i = 1;
$("tbody", this).find('tr').each(function() {
// find the correct td of the correct column
// we are considering the table column 1, You can apply on any table column
var Current_td = $(this).find('td:nth-child(' + Column_number_to_Merge + ')');

if (Previous_TD == null) {
// for first row
Previous_TD = Current_td;
i = 1;
} else if (Current_td.text() == Previous_TD.text()) {
// the current td is identical to the previous row td
// remove the current td
Current_td.remove();
// increment the rowspan attribute of the first row td instance
Previous_TD.attr('rowspan', i + 1);
i = i + 1;
} else {
// means new value found in current td. So initialize counter variable i
Previous_TD = Current_td;
i = 1;
}
});
});
}

HTML

<table class="table table-condensed col-md-12 result_table">
<thead style="border:solid black 1px;">
<td class="side">TEST</td>
<td class="tdbold">METHOD</td>
<td class="tdbold">COMPENDIA</td>
<td class="tdbold">SPECIFICATION</td>
<td class="tdbold">DETERMINED</td>
<td class="side">REMARKS</td>
</thead>
<tbody>
<tr valign="middle" align="center">
<td style="font-size:13px; " class="tbody_data side" rowspan="2">Assay</td>
<td valign="middle" align="center" style="padding: 0px;" class="tbody_data">
<input type="hidden" value="6" name="tests[]">
<textarea style="border: medium none; vertical-align: middle; height: 79px;" class="det_st form-control">HPLC</textarea>
</td>
<td style="padding: 0px;" class="tbody_data">
<textarea style="border: medium none; height: 79px;" class="det_st form-control">Adopted In-House Method</textarea>
</td>
<td style="padding: 0px;" class="tbody_data">
<textarea style="border: medium none; height: 79px;" class="det_st form-control">92.5 - 107.5%</textarea>
</td>
<td style="padding: 0px;" class="tbody_data">
<textarea style="border: medium none; height: 82px;" class="det_st form-control">Day 1 105.3% (RSD=1.5%; n=6)</textarea>
</td>
<td class="tbody_data side">
<select style="border:none; margin:15px; width:145px;" class="select" selected="selected">
<option value="COMPLIES">COMPLIES</option>
<option value="COMPLIES">COMPLIES</option>
<option value="DOES NOT COMPLY">DOES NOT COMPLY</option>
</select>
</td>
</tr>

<tr valign="middle" align="center">

<td valign="middle" align="center" style="padding: 0px;" class="tbody_data">
<input type="hidden" value="6" name="tests[]">
<textarea style="border: medium none; vertical-align: middle; height: 79px;" class="det_st form-control">HPLC</textarea>
</td>
<td style="padding: 0px;" class="tbody_data">
<textarea style="border: medium none; height: 79px;" class="det_st form-control">Adopted In-House Method</textarea>
</td>
<td style="padding: 0px;" class="tbody_data">
<textarea style="border: medium none; height: 79px;" class="det_st form-control">92.5 - 107.5%</textarea>
</td>
<td style="padding: 0px;" class="tbody_data">
<textarea style="border: medium none; height: 102px;" class="det_st form-control">Day 7 102.9% (RSD=0.27%; n=6)</textarea>
</td>
<td class="tbody_data side">
<select style="border:none; margin:15px; width:145px;" class="select" selected="selected">
<option value="COMPLIES">COMPLIES</option>
<option value="COMPLIES">COMPLIES</option>
<option value="DOES NOT COMPLY">DOES NOT COMPLY</option>
</select>
</td>
</tr>
</tbody>
</table>

最佳答案

我不完全确定你要做什么,但它看起来像这样:

if (Current_td.text() == Previous_TD.text())

可以更改为:

 if (Current_td.text() == Previous_TD.text()
|| Current_td.find("textarea").val() == Previous_TD.find("textarea").val())

关于javascript - 包含文本区域的行跨度表 td,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37700977/

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