【发布时间】:2021-09-22 04:22:12
【问题描述】:
我在这样的表格中有一个表格:
<form action="file.php" id="myform" method="POST">
<div class="table-responsive ">
<table class="table table-hover" id="tblDetalle">
<thead class="thead-dark">
<tr>
<th>Id</th>
<th>Name</th>
<th>Quant.</th>
<th>Price</th>
<th>Total Price</th>
</tr>
</thead>
<tbody">
<?php
if(!isset($_SESSION['products'])){
}else{
foreach($_SESSION['products'] as $product=>$details){
echo '
<tr class="txtMult">
<th scope = "row">'.$details["code_product"].'</th>
<th scope = "row">'.$details["name_product"].'</th>
<td><input class="val2" type="number" id="quantity" name="quantity" min="1" max="100"></td>
<td class="val1">'.$details["price"].'</td>
<td><span class="multTotal">0.00</span></td>
</tr>
';
};
}
?>
</tbody>
<tfoot>
<tr class="font-weight-bold">
<td colspan=4>Total <span id="grandTotal">0.00</span></td>
<td></td>
</tr>
</tfoot>
</table>
<input type="submit" value="Submit"/>
</div>
</form>
我的实际问题是提交按钮不起作用,单击按钮时未采取任何操作。 我的想法是通过 POST 方法将表的所有内容发送到 file.php。
有一个脚本最后更新价格*数量,但我认为问题不存在。
<script type="text/javascript">
$(document).ready(function () {
$(".txtMult input").keyup(multInputs);
function multInputs() {
var mult = 0;
// for each row:
$("tr.txtMult").each(function () {
// get the values from this row:
var $val1 = parseInt($('.val1', this).text())
var $val2 = $('.val2', this).val();
var $total = ($val1 * 1) * ($val2 * 1)
$('.multTotal',this).text($total);
mult += $total;
});
$("#grandTotal").text(mult);
}
});
</script>
有人可以帮忙吗? :)
【问题讨论】:
-
在第 13 行,将 更改为 并重试在 PHP 循环中,您重复
id="quantity"~ ID 必须是唯一的。输入元素quantity如果您希望为其发送多个值,则应将其命名为quantity[]。看起来这是唯一的输入元素,但据我所知,无法确定哪个数量指的是哪个产品不能通过post表单获取整个表格,只能通过该方法获取输入字段值,然后需要在该file.php页面上用post表单数据排列表格