我有这个 JS 和 HTML 代码:
当您单击添加按钮时,它会运行以下函数以将另一行添加到 HTML 表中,并在每次计数 1 后添加更多带有数字的表单字段
<script language="javascript" type="text/javascript">
var i=2;
function addRow()
{
var tbl = document.getElementById('table1');
var lastRow = tbl.rows.length;
var iteration = lastRow - 1;
var row = tbl.insertRow(lastRow);
var productcodeCell = row.insertCell(0);
var elproductcode = document.createElement('input');
elproductcode.type = 'text';
elproductcode.name = 'productcode' + i;
elproductcode.id = 'productcode' + i;
elproductcode.size = 20;
productcodeCell.appendChild(elproductcode);
var producttitleCell = row.insertCell(1);
var elproducttitle = document.createElement('input');
elproducttitle.type = 'text';
elproducttitle.name = 'producttitle' + i;
elproducttitle.id = 'producttitle' + i;
elproducttitle.size = 30;
producttitleCell.appendChild(elproducttitle);
var quantityCell = row.insertCell(2);
var elQuantity = document.createElement('input');
elQuantity.type = 'text';
elQuantity.name = 'quantity' + i;
elQuantity.id = 'quantity' + i;
elQuantity.size = 10;
quantityCell.appendChild(elQuantity);
i++;
form1.number.value=i;
//alert(i);
}
</script>
<form method="post" action="create_quote2.php" name="form1">
<input type="button" value="Add New Line" onclick="addRow();" />
<table width="800" border="0" cellspacing="5" cellpadding="5" id="table1">
<tr>
<td><strong>Product Code</strong></td>
<td><strong>Title</strong></td>
<td><strong>Add</strong></td>
<td><strong>Qty</strong></td>
</tr>
<tr>
<td><input type="text" name="productcode1" id="productcode1" size="20" /></td>
<td><input type="text" name="producttitle1" id="producttitle1" size="30" /></td>
<td><a href="page.php?c=1">Link here</a></td>
<td><input type="text" name="quantity1" id="quantity1" size="10" /></td>
</tr>
</table>
<input type="hidden" name="number" id="number" value="1" />
</form>
添加行时如何在第 3 列中添加链接,并且每次都像其他字段一样更改 URL + 1 中的结束编号