- 为什么 2 数组不能按 + 或 -
- 所以我想得到这个价格和数量将求和并获得数量价值
当您还和价格和系统将以金额形式获取价值时,下面的总额将发生变化(它从金额中提取)
<table class="table table-striped table-hover"> <thead> <tr> <th class="span1" style="text-align:center;">Delete</th> <th class="span12" style="text-align:center;">Name</th> <th class="span2" style="text-align:center;">Price</th> <th class="span2" style="text-align:center;">Quantity</th> <th class="span2" style="text-align:center;">Amount</th> </tr> </thead> <tbody> <tr> <td style="text-align:center; vertical-align:middle;"> <a class="btn-danger" href=""><i class="icon-remove icon-white"></i></a> </td> <td style="text-align:left; vertical-align:middle;">test</td> <td style="text-align:center; vertical-align:middle;">24</td> <td style="text-align:center; vertical-align:middle;"> <div class="input-append"> <input class="input-mini" type="text" id="quantity[]" name='prd_num[]' value='1' style="text-align:center;"> <button class="btn" type="button" id="up"><i class="icon-plus"></i></button> <button class="btn" type="button" id="down"><i class="icon-minus"></i></button> </div> </td>+63 <td style="text-align:right; vertical-align:middle;"></td> </tr> <tr> <td style="text-align:center; vertical-align:middle;"> <a class="btn-danger" href=""><i class="icon-remove icon-white"></i></a> </td> <td style="text-align:left; vertical-align:middle;">test</td> <td style="text-align:center; vertical-align:middle;">24</td> <td style="text-align:center; vertical-align:middle;"> <div class="input-append"> <input class="input-mini" type="text" id="quantity[]" name='prd_num[]' value='1' style="text-align:center;"> <button class="btn" type="button" id="up"><i class="icon-plus"></i></button> <button class="btn" type="button" id="down"><i class="icon-minus"></i></button> </div> </td>+63 <td style="text-align:right; vertical-align:middle;"></td> </tr> </tbody> <tfoot> <tr> <td colspan="3"></td> <td style="text-align:center; vertical-align:middle;"> <strong>Total</strong> </td> <td style="text-align:right; vertical-align:middle;"></td> </tr> </tfoot> </table>
JavaScript如下:
button_up=document.getElementById('up');
button_down=document.getElementById('down');
button_up.onclick=function() {setQuantity('up');}
button_down.onclick=function() {setQuantity('down');}
quantity = document.getElementById('quantity[]');
function setQuantity(upordown) {
if (quantity.value > 1) {
if (upordown == 'up') {++quantity.value;}
else if (upordown == 'down') {--quantity.value;}
}
else if (quantity.value == 1) {
if (upordown == 'up') {++quantity.value;}
}
else
{quantity.value=1;}
}