![](/img/trans.png)
[英]Get contents of the first cell in the clicked column and the first cell of the clicked row in a HTML table
[英]get item from table cell and append to first cell within same row
如何从表格内的TD抓取文本并将其插入同一行的第一个TD? -使用jQuery
<table border=1>
<tbody>
<tr>
<td>APPEND TEXT1 HERE</td>
<td></td>
<td>GRAB TEXT1 HERE</td>
</tr>
<tr>
<td>APPEND TEXT2 HERE</td>
<td></td>
<td>GRAB TEXT2 HERE</td>
</tr>
<tr>
<td>APPEND TEXT3 HERE</td>
<td></td>
<td>GRAB TEXT3 HERE</td>
</tr>
</tbody>
</table>
$('table td:first-child').text(function(){
return $(this).siblings().last().text()
})
如果您要附加文本( 而不是替换 ):
$('table td:first-child').text(function(i, c){
return c + ' ' + $(this).siblings().last().text()
})
遍历每一行,并将td
中的文本以所需的偏移量附加到第一行:
$('tr').each(function(){
$(this).find('td').eq(0).append($(this).find('td').eq(2).text());
});
这是一个演示: http : //jsfiddle.net/pchEG/
循环遍历每个<tr>
并从最后一个<td>
子元素中获取.html()
。
$('tr').each(function(idx){
var appendToNode = $(this).find('td:first-child');
// And append to the existing HTML.
appendToNode.html(appendToNode.html() + $(this).find('td:last-child').html());
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.