Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在html中将行动态添加到表格中,表格数据作为文本框_Jquery - Fatal编程技术网

Jquery 在html中将行动态添加到表格中,表格数据作为文本框

Jquery 在html中将行动态添加到表格中,表格数据作为文本框,jquery,Jquery,我有一个表,有两个cloumns PartNumber和Quantity作为列标题。每一行都是一个可编辑的文本框,具有用于通过网络发送数据的特定ID。表结构如下所示 <tr> <th>Part Number</th> <th>Quantity</th> </tr> <tr> <td><input type="text" id="t1"></td> <td><i

我有一个表,有两个cloumns PartNumber和Quantity作为列标题。每一行都是一个可编辑的文本框,具有用于通过网络发送数据的特定ID。表结构如下所示

<tr>
<th>Part Number</th>
<th>Quantity</th>
</tr>
<tr>
<td><input type="text" id="t1"></td>
<td><input type="number" id="q1"></td>
</tr>
<tr>
<td><input type="text" id="t2"></td>
<td><input type="number" id="q2"></td>
</tr>
--
--
--
<tr>
<td><input type="text" id="t5"></td>
<td><input type="number" id="q5"></td>
</tr>

零件号
量
--
--
--
点击按钮,我必须将数据发送到webservice进行进一步处理


我的新任务是在单击addrow按钮时动态添加行。添加带有文本框的行不是问题。。问题在于为每个字段分配ID。即。。下一行的ID应为“t6”和“q6”。如何执行此操作

您只需将行号附加到每个字段的
ID
属性

以下是您在粗略代码中需要遵循的流程:

var rowNumber = $('table tr').length + 1;
$('#newRow input').attr('id', 't' + rowNumber);
$('#newRow').appendTo('table');

在动态添加带有文本框的行的地方包含jquery代码。