【发布时间】:2021-05-20 15:29:13
【问题描述】:
我的问题是如何使用 [$i] 从动态输入文本中获取元素 id 值
<input type='text' class='form-control num-only 'id='price[$i]' />
完整代码:
<html>
<body>
<p id="demo">Create Invoice</p>
<table class="table table-bordered table-responsive" id="crud_table">
<tr>
<th class="" >#</th>
<th class="" >Product</th>
<th class="" >Item Price</th>
<th class="" >Quantity</th>
<th class="" >inStore</th>
<th class="" >New Quantity</th>
<th class="" >Total</th>
</tr>
<tbody>
<?php for ($i = 1; $i <= 2; $i++) {
echo"
<tr>
<td align='center'><?php echo $i;?></td>
<td><input type='text' class='form-control ' value='' id='itemname[$i]' /></td>
<td><input type='text' class='form-control num-only ' id='price[$i]' /></td>
<td><input type='number' class='form-control num-only' maxlength='5' id='quantity[$i]' onchange='kofta(this)'/></td>
<td><input type='text' class='form-control num-only' maxlength='50' id='inStore[$i]' onchange='kofta()'/></td>
<td><input type='text' class='form-control num-only' maxlength='10' id='newq[$i] ' onchange='kofta()'/></td>
<td><input type='text' class='form-control num-only' maxlength='50' id='total[$i]' readonly /></td>
</tr> ";
} ?>
</tbody>
</table>
<input type="text" id="total" readonly value="0">
<script>
function kofta(){
var rate= document.getElementById("price").value;
var q1=document.getElementById("quantity").value
var total= rate * q1;
document.getElementById("total").value=total;
}
</script>
我怎样才能获得价值?所以我可以计算值 总计 = 价格 * 数量 总输入文本中所有行的总和
【问题讨论】:
标签: javascript