将行动态添加到表中 [英] Adding rows dynamically into a table

查看:60
本文介绍了将行动态添加到表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求:

在现有表格中动态追加两行。



第1步:最初表格中没有行。



一个名为AddField的按钮。

对于每个按钮,请单击重复以下步骤。



第2步:在表格中添加了两行。



如何可以使用javascript。



请在asp.net mvc3中提供解决方案。



MyCode:

Requirement:
Appending two rows dynamically in a existing table.

Step 1: Initially table contains no rows.

A button named as AddField .
For each button click repeat the following step.

Step 2: two rows added to the table.

How it is possible using javascript.

Please provide a solution in asp.net mvc3.

MyCode:

$('#Field tr').length;//first i take the current number of tr. 
Here 'Field' is my table id.
then using the following code i append one row below the current row.
 $('.AddTableRowForm').append(//Inside this i specified all controls which are added on each row.)



输出:

附加一行指定控件。



实际输出:

在当前行下面添加两行。



谢谢&此致,

Anupama


Ouput:
appended one row with specified controls.

Actual Output:
Append two rows below the current row.

Thanks& Regards,
Anupama

推荐答案

' #Field tr')。length; // 首先我取当前的tr数。
这里' 字段'是我的表ID。
然后使用以下代码我在当前行下面添加一行。
('#Field tr').length;//first i take the current number of tr. Here 'Field' is my table id. then using the following code i append one row below the current row.


' 。AddTableRowForm')。append( // 在此我指定了所有控件在每一行上添加。)
('.AddTableRowForm').append(//Inside this i specified all controls which are added on each row.)



输出:

附加一行指定的控件。



实际输出:

在当前行下方添加两行。



谢谢&问候,

Anupama


Ouput:
appended one row with specified controls.

Actual Output:
Append two rows below the current row.

Thanks& Regards,
Anupama


您正在使用的append语句在表中附加一行。所以很多时候你写这个语句会把很多行附加到你的表中。

因为在你的情况下你有2个这样的行,只需写两次append语句:

The append statement you are using appends a row to the table. So as many times you write that statement it will append that many rows to your table.
Since in your case you 2 such rows, just write the append statement two times:


这篇关于将行动态添加到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆