使用jquery在客户端的转发器内的表中添加行

时间:2022-06-18 15:14:16

I have a repeater which contains a table. I am giving the user the ability to add a new row in the repeater by adding a new row to the table.

我有一个包含一张桌子的转发器。我通过向表中添加新行,让用户能够在转发器中添加新行。

Can anyone give me ideas? As I am very new to jQuery, can someone give sample code?

有人能给我点子吗?由于我是jQuery的新手,有人可以提供示例代码吗?

1 个解决方案

#1


6  

If you look at the jQuery manipulation methods these are the methods for modifying the DOM in jQuery.

如果你看一下jQuery操作方法,这些是在jQuery中修改DOM的方法。

I would suggest for what you are doing something along the lines of:

我会建议你做的事情是这样的:

var tableToUpdate = $('#yourTableId'); // select the table
var rowToAdd = $('<tr></tr>'); // this will create a table row element
rowToAdd.append('<td>some content for this cell</td>'); // add the columns to your new row
tableToUpdate.append(rowToAdd); // append the row to the end of the table

This will insert a new row at the end of the table. If your table has a tbody (you will have to modify your initial selector to '#yourTableId tbody'.

这将在表的末尾插入一个新行。如果你的表有一个tbody(你必须将你的初始选择器修改为'#yourTableId tbody'。

To insert the new row in different positions within the table look though the other manipulation methods - after, before, prepend etc.

要在表中的不同位置插入新行,请查看其他操作方法 - 之前,之前,前置等。

Hope this helps, if you are able to be a little more specific about the situation, I can probably give you a more concrete example.

希望这有帮助,如果你能够更具体地了解情况,我可以给你一个更具体的例子。

#1


6  

If you look at the jQuery manipulation methods these are the methods for modifying the DOM in jQuery.

如果你看一下jQuery操作方法,这些是在jQuery中修改DOM的方法。

I would suggest for what you are doing something along the lines of:

我会建议你做的事情是这样的:

var tableToUpdate = $('#yourTableId'); // select the table
var rowToAdd = $('<tr></tr>'); // this will create a table row element
rowToAdd.append('<td>some content for this cell</td>'); // add the columns to your new row
tableToUpdate.append(rowToAdd); // append the row to the end of the table

This will insert a new row at the end of the table. If your table has a tbody (you will have to modify your initial selector to '#yourTableId tbody'.

这将在表的末尾插入一个新行。如果你的表有一个tbody(你必须将你的初始选择器修改为'#yourTableId tbody'。

To insert the new row in different positions within the table look though the other manipulation methods - after, before, prepend etc.

要在表中的不同位置插入新行,请查看其他操作方法 - 之前,之前,前置等。

Hope this helps, if you are able to be a little more specific about the situation, I can probably give you a more concrete example.

希望这有帮助,如果你能够更具体地了解情况,我可以给你一个更具体的例子。