我正在使用下面的代码将数量乘以价格。该代码工作正常,但是当我有不止一行时,它会将第一行的价格添加到第二行
如何使价格仅显示该行而不显示前一行?
我已经创建了一个小提琴来展示我正在尝试做的事情
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>demo</title>
<script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>
<style type='text/css'>
</style>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
$('.minus, .plus').click(function (e) {
e.preventDefault();
var $input = $(this).siblings('.qty');
var val = parseInt($input.val(), 10);
$input.val(val + ($(this).hasClass('minus') ? -1 : 1));
});
});//]]>
</script>
<script type='text/javascript'>//<![CDATA[
$(function(){
$('.minus, .plus').click(function () {
var sibs = $(this).siblings();
var quantity = $('.qty').val();
var priceItem = sibs.filter(".price").val();
var total2 = quantity * priceItem;
var total = (+total2 + +priceItem);
sibs.filter(".total").val(total);
});
});//]]>
</script>
</head>
<body>
<?php
$x=1;
while($x<=5)
{
?>
<div>Qty:
<span class='minus' class="signrm">—</span> <input type="text" name="qty" class="txt qty" value="1" /> <span class='plus' >+</span>
<br/>Price:
<input type="text" name="price" class="txt price" value="500" />
<br/>Total:
<input type="text" name="total" class="txt total" value="500" />
</div>
<?php
$x++; } ?>
</body>
</html>