本文介绍了如何使用jquery / javascript从动态生成的html表中删除一行(具有下拉列表,文本框等多行控件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个TR,里面有多个控件
即< tr>下拉列表,textboxex,datepickers,..< / tr>
Iam多次使用不同的ID添加相同的行并具有一些验证(javascript)
之间的比较行。
如何在点击按钮时删除所选/特定/选中的行?
我删除了一行,我的验证工作不正常,我有for循环,因为
动态地将IDS添加到动态生成的控件中。
I have one TR with multiple controls in it
i.e <tr> dropdown list,textboxex ,datepickers,..</tr>
Iam adding the same row multiple time with different IDs and have some validtions(javascript)
comparisions between the rows.
How to delete selected/specific/checked row on clicking of a button?
When i delete a row my validations are not working properly which i have in for loops because
am adding IDS dynamically to my controls which are generated dynamically.
推荐答案
<html>
<head>
<title> Add/Remove dynamic rows in HTML table </title>
<script language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
element1.name="chkbox[]";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount + 1;
var cell3 = row.insertCell(2);
var element2 = document.createElement("input");
element2.type = "text";
element2.name = "txtbox[]";
cell3.appendChild(element2);
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i
</script></head>
<body>
<input type="button" value="Add Row" onclick="addRow('dataTable')" />
<input type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
<input type="checkbox" name="chk" />
1
<input type="text" />
</body>
</html>
这篇关于如何使用jquery / javascript从动态生成的html表中删除一行(具有下拉列表,文本框等多行控件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!