从表中删除行后,动态id不起作用
Dynamic id does not work after removing row from table
我有一个表与feesettingid。它包含动态数据,我可以添加和删除删除行表。我动态生成的id工作良好,直到用户删除一行并再次添加新行,它覆盖最后一行的唯一id。我想表生成唯一的id与动态添加和删除功能。我的代码添加行如下。
<tablen id="feeSetting ">
<tbody>
</tbody>
</table>
<script>
function AddRow() {
debugger;
var index = 0;
if ($("#feeSetting tbody tr").length > 0) {
index = $("#feeSetting tbody tr").length;
}
$("#feeSetting tbody").append("<tr class='gradeX'>"
+ "<td class='col-md-3'><input type='text' value='' class='form-control validate[required,custom[number]] text-input txtFromDay' id='eFromDay'/></td>"
+ "<td class='col-md-3'><input type='text' class='form-control validate[required,custom[number],min[1]] text-input txtValue' value='' id='eValue-" + index + "'/></td>"
+ "<td class='col-md-4'>"
+ "<div id='loadTypes-" + index + "' class='typeValidation'></div></td>"
+ "<td class='col-md-2'><input type='button' class='btn btn-danger btn-sm' value=' Remove '/></td>"
+ "</tr>");
renderPartialInDiv('@Url.Action("GetValidationTypeDropDown", "FeeFineSetting")?strDDName=eValidationTypeList-' + index + '&intDDID=0&intValidationID=1', '#loadTypes-' + index);
$('#eValidationTypeList-'+index).select2();
};
</script>
尝试使用一个全局变量,它将在每增加一行时增加其值,参见下面的代码
<tablen id="feeSetting ">
<tbody>
</tbody>
</table>
<script>
//keep this variable outside function and use it as global variable.
var index = 0;
function AddRow() {
debugger;
index++;
$("#feeSetting tbody").append("<tr class='gradeX'>"
+ "<td class='col-md-3'><input type='text' value='' class='form-control validate[required,custom[number]] text-input txtFromDay' id='eFromDay'/></td>"
+ "<td class='col-md-3'><input type='text' class='form-control validate[required,custom[number],min[1]] text-input txtValue' value='' id='eValue-" + index + "'/></td>"
+ "<td class='col-md-4'>"
+ "<div id='loadTypes-" + index + "' class='typeValidation'></div></td>"
+ "<td class='col-md-2'><input type='button' class='btn btn-danger btn-sm' value=' Remove '/></td>"
+ "</tr>");
renderPartialInDiv('@Url.Action("GetValidationTypeDropDown", "FeeFineSetting")?strDDName=eValidationTypeList-' + index + '&intDDID=0&intValidationID=1', '#loadTypes-' + index);
$('#eValidationTypeList-'+index).select2();
};
</script>
相关文章:
- 使用getElementById设置动态ID的输入字段的样式
- Javascript:获取具有动态id的文本框值
- 如何添加动态Id's并在运行时提取它们
- 在追加一行并调用其中的时差函数时生成动态id
- 如何将所有动态id的arrey值获取到javascript VAR CID,以便在sql中找到匹配项
- 将动态ID传递到成功主干上的url
- 通过向动态id添加字符串,使用JavaScript控制文本框
- 如何简化Javascript动态ID
- 提交具有动态id的表单的数据
- 为jquery分配动态id
- 骨干路由器.导航如何传递动态ID
- 如何将动态 ID 值分配给标签
- 给出动态 id Angular2 绑定
- 如何在 PHP 和数据库中的 OpenTracker() 中传递动态 ID
- 选择具有动态 ID 的特定 tr 的特定 td
- 如何在javascript中使用动态ID删除文本框
- 如何在 javascript 中处理具有动态 ID 的事件
- 如何使用 getElementById 和 c# 变量设置动态 id
- 尝试将列表项追加到动态 id
- 如何在 jQuery 中创建动态 ID