我有一张桌子用于输入每日股票报告,每个表格单元格都是类型编号的输入文件。我想对表中的每一行执行一些计算。每当输入字段值改变时,我都要执行每行的计算。请参阅下面的图片以便更好地理解:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="stock-table">
<thead>
<tr>
<th>S.No.</th>
<th>Name of the Material</th>
<th colspan="2">Opening Stock</th>
<th colspan="2">Receipts</th>
<th colspan="2">Issues</th>
<th colspan="2">Closing Stock</th>
</tr>
</thead>
<tbody id="stock_report">
<tr>
<td></td>
<td></td>
<td>Bags</td>
<td>MT</td>
<td>Bags</td>
<td>MT</td>
<td>Bags</td>
<td>MT</td>
<td>Bags</td>
<td>MT</td>
</tr>
<tr>
<tr>
<td>1</td>
<td>Boiled Bran</td>
<td>
<input type="number" step="0.001" name="bbo_bags" id="bbo_bags">
</td>
<td>
<input type="number" step="0.001" name="bbo_mt" id="bbo_mt">
</td>
<td>
<input type="number" step="0.001" name="bbr_bags" id="bbr_bags">
</td>
<td>
<input type="number" step="0.001" name="bbr_mt" id="bbr_mt">
</td>
<td>
<input type="number" step="0.001" name="bbi_bags" id="bbi_bags">
</td>
<td>
<input type="number" step="0.001" name="bbi_mt" id="bbi_mt">
</td>
<td>
<input type="number" step="0.001" name="bbc_bags" id="bbc_bags">
</td>
<td>
<input type="number" step="0.001" name="bbc_mt" id="bbc_mt">
</td>
</tr>
</tr>
</tbody>
</table>
FirstViewController
答案 0 :(得分:0)
$("#stock_report").delegate('#bbo_bags', 'change', function (event) {
var bbo_bags = parseFloat($('#bbo_bags').val());
$("#stock_report #bbc_bags").val(bbo_bags);
});
$("#stock_report").delegate('#bbr_bags', 'change', function (event) {
var bbo_bags = parseFloat($('#bbo_bags').val());
var bbr_bags = parseFloat($('#bbr_bags').val());
var tot=bbo_bags - bbr_bags ;
$("#stock_report #bbc_bags").val(tot);
});
$("#stock_report").delegate('#bbi_bags', 'change', function (event) {
var bbo_bags = parseFloat($('#bbo_bags').val());
var bbr_bags = parseFloat($('#bbr_bags').val());
var bbi_bags = parseFloat($('#bbi_bags').val());
var tot=bbo_bags - bbr_bags + bbi_bags;
$("#stock_report #bbc_bags").val(tot);
});
$("#stock_report").delegate('#bbo_mt', 'change', function (event) {
var bbo_mt = parseFloat($('#bbo_mt').val());
$("#stock_report #bbc_mt").val(bbo_mt);
});
$("#stock_report").delegate('#bbr_mt', 'change', function (event) {
var bbo_mt = parseFloat($('#bbo_mt').val());
var bbr_mt = parseFloat($('#bbr_mt').val());
var tot=bbo_mt - bbr_mt ;
$("#stock_report #bbc_mt").val(tot);
});
$("#stock_report").delegate('#bbi_mt', 'change', function (event) {
var bbo_mt = parseFloat($('#bbo_mt').val());
var bbr_mt = parseFloat($('#bbr_mt').val());
var bbi_mt = parseFloat($('#bbi_mt').val());
var tot=bbo_mt - bbr_mt + bbi_mt;
$("#stock_report #bbc_mt").val(tot);
});
更新您的脚本以进行计算。我希望这段代码能够解决问题。