在表中插入新行 [英] Insert new row in Table
本文介绍了在表中插入新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到一个问题,:eq()
不接受计数器 n
,以插入值到HTML中的表的新列。
I have a problem where the :eq()
does not accept the counter, n
, to insert values to a new column to the table in the HTML.
$(document).ready(function() {
var $tablerow = $('table.table').find('tr');
count = 0;
$tablerow.each(function(index, value){
count += 1;
var $listitem = $(this);
n = parseInt($listitem.index());
var $newRow = $("<td>" + n + "</td>");
$("table.table tr:eq(n)").append($newRow);
});
});
HTML
<table class="table">
<tr><td>First row</td></tr>
<tr><td>second row</td></tr>
<tr><td>third row</td></tr>
<tr><td>fourth row</td></tr>
<tr><td>fifth row</td></tr>
<tr><td>sixth row</td></tr>
<tr><td>seventh row</td></tr>
<tr><td>eighth row</td></tr>
</table>
推荐答案
按原样写,你什么都没做而不是将文字字符'n'写入 .eq()
方法。试试这个:
Written as-is, you're doing nothing more than writing a literal character, 'n', into .eq()
method. Try this:
$("table.table tr:eq(" + n + ")").append($newRow);
这篇关于在表中插入新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文