【发布时间】:2013-06-14 14:33:56
【问题描述】:
我有一张表,它只包含一行。 Row 有很多元素,例如文本框和按钮。当我单击按钮时,表格行将使用append() 函数进行克隆。我的问题是当我单击按钮时,我想增加文本框和按钮 ID。我该怎么做?
示例 HTML:
<tr id="items:1">
<td id="id">
<input type="text" id="price:1" name="price" value="" size="6" readonly="readonly" />
</td>
<td id="id">
<input type="text" id="quantity:1" name="quantity" size="10" align="middle" onblur="totalprice(this)" />
</td>
<td id="id">
<input type="text" id="total:1" name="total" size="10" value="0" readonly="readonly" align="middle" />
</td>
<td id="id">
<input type="button" onclick="cloneRow()" id="button:1" value="ADD" />
</td>
</tr>
示例 JavaScript:
function cloneRow() {
var row = document.getElementById("items:1");
var table = document.getElementById("particulars");
var clone = row.cloneNode(true);
var rowId = "items:" + a.toString();
clone.id = rowId;
var tabledataid = document.getElementById("id");
var inputtext = tabledataid.getElementsByTagName("input");
var inputtextid = inputtext[a];
var changeInputTextid = "price:" + b.toString();
inputtextid.id = changeInputTextid;
alert(changeInputTextid);
table.appendChild(clone);
a++;
}
【问题讨论】:
-
告诉我们你有什么
-
把你的代码放在有问题的地方,以便阅读
标签: javascript html