我有一张这样的桌子:
<thead>
<tr class="row-2"><tr>
<tr class="row-3">..<tr>
<tr class="row-4">..<tr>
<tr class="row-5">..<tr>
<tr class="row-6">..<tr>
<tr class="row-7"><tr>
<tr class="row-8">..<tr>
<tr class="row-9">..<tr>
<tr class="row-10">..<tr>
<tr class="row-11">..<tr>
</thead>如何使用jQuery将所有tr标记替换为can标记中的th标记?
发布于 2010-12-07 16:21:30
获取表html,然后使用th replace所有实例或tr (有关更多信息,请参见RegExp )。您可以将设置为具有id并访问该id。
$('#tableId').html($('#tableId').html().replace(/tr/gi, 'th'));这会将整个表中的所有tr更改为th。
多亏了jAndy,可以编辑以获得更好的性能。
$('#mytable').find('tr').each(function() {
var $this = $(this);
$this.replaceWith('<th class="' + this.className + '">' + $this.text() + '</th>');
});.find()比$('#mytable > tr')快吗?
https://stackoverflow.com/questions/4374595
复制相似问题