我在这里做一个懒惰的表格转置。 我有一个像这样的表格:
<table>
<th style="text-align: left; text-transform: capitalize;">Unique</th>
<th style="text-align: left; text-transform: capitalize;">x1</th>
<th style="text-align: left; text-transform: capitalize;">y2</th>
<tr class="rowNormal">
<td nowrap="true">a1</td>
<td nowrap="true">b2</td>
<td nowrap="true">b3</td>
</tr>
</table>
我需要让它看起来像这样:
。
<table>
<tr class="rowNormal">
<tr><td nowrap="true">a1</td><.tr>
<tr><td nowrap="true">b2</td></tr>
<tr><td nowrap="true">b3</td></tr>
</tr>
</table>
它只有两行,其中之一是标题行。 因此我这样隐藏标题行:
$("table:contains('Unique')").find("th").addClass("hidden");
这段代码目前运行良好。现在我需要为每个<td nowrap="true">
添加一个<tr>
,但是我在这里遇到了麻烦。我尝试使用以下代码:
$('div.content').html($('div.content').html().replace(/<td nowrap="true">/g,' <tr><td nowrap="true">'));
这段代码是可行的,但我想将其限定在包含“Unique”的表格中,而不使用全局变量。 这样:
$('div.content').html($('div.content').html().replace(/</td>/g,'<td></tr>'));
完全不起作用。 我尝试使用replaceWith
和replaceAll
,但未能成功。
问题:
1)最佳方法是添加格式以将剩余行转置为列吗?
2)我如何指定"
和/
作为参数?
3)'
和"
之间有什么区别?
感谢您的时间。
/
。 - Sanchit$('td').wrap('tr')
吗? - Pedro Estrada