【发布时间】:2016-10-16 02:48:53
【问题描述】:
我需要计算数量乘以单价输入,相等的输入将是小计并将所有小计相加......
我在 javascript 中使用了这段代码,它工作正常,但在表中没有工作。
请帮忙。
HTML/PHP:
<table border="0" cellspacing="0" class="table table-bordered table-hover" data-name="cont-table">
<thead style="">
<tr>
<th class="check-this"><input class="check_all" type="checkbox" onclick="select_all()"/></th>
<th class="text-center"> م </th>
<th class="text-center"> اسم الصنف </th>
<th class="text-center"> الوحدة </th>
<th class="text-center"> الكمية </th>
<th class="text-center"> سعر الوحدة </th>
<th class="text-center"> العام المالي </th>
<th class="text-center"> إجمالي قيمة الصنف </th>
</tr>
</thead>
<tr>
<td><input type="checkbox" class="case"/></td>
<td><span id="snum">1.</span></td>
<td><!--<input type="text" id="first_name" name="first_name[]"/>!-->
<select class="select" id="first_name" name="first_name[]">
<?php
$stmt = $db->query("SELECT first_name6 FROM item");
//$stmt = $pdo->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<option >" . $row['first_name6'] . "</option>";
}
?>
</select></td>
<td><!--<input type="text" id="last_name" name="last_name[]"/>!-->
<select class="select" id="first_name" name="first_name[]">
<?php
$stmt = $db->query("SELECT first_name7 FROM unit");
//$stmt = $pdo->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<option >" . $row['first_name7'] . "</option>";
}
?>
</select></td>
<td><input class="select qty" type="number" id="tamil" name="tamil[]"/></td>
<td><input class="select unit" type="number" id="english" name="english[]" /></td>
<td><!--<input type="text" id="computer" name="computer[]"/>!-->
<select class="select " id="first_name" name="first_name[]">
<?php
$stmt = $db->query("SELECT first_name8 FROM financial");
//$stmt = $pdo->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<option >" . $row['first_name8'] . "</option>";
}
?>
</select></td>
<td><input type="text" id="total" class="amount" value="" /></td>
</tr>
</table>
<button id="add_row" type="button" class="delete btn btn-default pull-right">مسح</button>
<button id="add_row" style="margin-right:5px;" type="button" class="addmore btn btn-default pull-right">اضاف صنف</button>
<br>
<br>
<h3 class="table-h3 " style="text-align:center;">اجمالي قيمة العقد</h3>
<input type="text" name="totalprice" class="result" value="" />
这是javascript代码:
$(".qty").on('input', function () {
var self = $(this);
var unitVal = self.next().val();
self.next().next().val(unitVal * self.val());
fnAlltotal();
});
$(".unit").on('input', function () {
var self = $(this);
var qtyVal = self.prev().val();
self.next().val(qtyVal * self.val());
fnAlltotal();
});
function fnAlltotal(){
var total=0
$(".amount").each(function(){
total += parseFloat($(this).val()||0);
});
$(".result").val(total);
}
【问题讨论】:
标签: javascript php jquery