我有一个按钮,一旦你点击它,它会在现有的表中插入一个新行。我遇到的问题是我必须第一次点击两次才会插入新行。但之后,每次单击一次,都会插入行。
按钮:
<input type="button" id="add_po_item" name="add_po_item" value="Add Next PO Item" class="btn" style="width:150px; visibility:visible" onclick="addStock(this, '<?php echo $prod_id; ?>', '<?php echo $poid; ?>'); ">
javascript函数添加新行:
function addStock(obj, stock_id, poid)
{
var inputs = document.getElementById('counter').value*1;
var elemName = "hid"+inputs;
if(obj.id == 'add_po_item')
{
$('#' + elemName).load("grn_additem.php", { inputs: inputs, stock_id: stock_id, poid: poid } );
}
inputs++;
var table = document.getElementById("add");
var elem = document.createElement("tr");
elem.id = "hid" + inputs;
table.appendChild(elem);
document.getElementById('counter').value = inputs;
}
grn_additem.php中的内容
<td width="144"><input type="text" id="ttlM3_<?php echo $ctr; ?>" name="ttlM3_<?php echo $ctr; ?>" readonly="readonly" style="border:none; text-align:center" value="0" /></td>
<td width="144"><input type="text" id="m31_<?php echo $ctr; ?>" name="m31_<?php echo $ctr; ?>" onkeyup="calcM3('<?php echo $ctr; ?>')" /></td>
<td width="144"><input type="text" id="m32_<?php echo $ctr; ?>" name="m32_<?php echo $ctr; ?>" onkeyup="calcM3('<?php echo $ctr; ?>')" /></td>
<td width="144"><input type="text" id="m33_<?php echo $ctr; ?>" name="m33_<?php echo $ctr; ?>" onkeyup="calcM3('<?php echo $ctr; ?>')" /></td>
<td width="45"> </td>
<td width="144"><input type="text" id="matchcolor<?php echo $ctr; ?>" name="matchcolor<?php echo $ctr; ?>" readonly="readonly" style="background-color:#FF0000" /></td>